While Loops In Swift

We have observed kind of similar syntax for while loop in every other programming languages. In Swift we use while to repeat a block of code until a condition changes. The condition of a loop can be at the end instead, ensuring that the loop is run at least once.

var n = 5
while n < 100 {
   n+=5
}
print(n)

Leave a Reply

Your email address will not be published. Required fields are marked *