Wednesday 12 October 2016

Loops in Swift3.0

Swift provides  two types of  for loops.
1) for - in loop
2) for  loop

for - in 















Note*
Swift3.0 remove old C style looping. 

















 for loop  in swift 3.0 













While Loop 
A while loop performs a set of statements until a condition becomes false. These kinds of loops are best used when the number of iterations is not known before the first iteration begins. Swift provides two kinds of while loops:

1)while evaluates its condition at the start of each pass through the loop.

2)repeat-while evaluates its condition at the end of each pass through the loop.

while loop

 syntax

 while (condition) {
   // statements
}















Repeat-While Loop
It will execute at least once before checking the condition. Apple chooses to call it repeat-while instead of do-while for making the working of the loop more consistent with it’s name.
Syntax
repeat {
// statements
}while condition

NOTE*
The repeat-while loop in Swift is analogous to a do-while loop in other languages.














1 comment: