When you know how many times you need to run some code then FOR loop is best.
For example, array-dictionary traversal
Whereas, WHILE loop is best when you don't know how many times some code will run.
For example, in a LinkedList traversal, we don't know how many nodes are there in the linked list. We will go through each node until it becomes nil.
Note: In many cases, you can use them vice-versa.
Topic:
Developer Tools & Services
SubTopic:
Swift Playground
Tags: