5.3. Repeat loops
The third way of writing loops is repeat loops. It is identical to a while loop, but the condition is checked at the end of the code block. If we use the same example from before, we can write:
var myNum = 1
repeat{
//code block
print(myNum)
myNum += 1
} while myNum <= 50
The point is repeat loops will execute the code block at least once. So, you should be careful about the cases where the first iteration may result in errors.
Last updated
Was this helpful?