Loops
For Loop and While Loop.
While Loop
Syntax of While loops follow the same convention as other languages.:
while <condition> {
<statements>
}Example:
var i = 0
while i < 5 {
print(string(i) + " ")
i = i + 1
}
// 0 1 2 3 4For Loop
Syntax of For Loops deviates slightly from usual convention:
for <variable> = <start> to <end> {
<statements>
}Here <variable> can be accessed inside the for loop as well as changed inside the loop.
Value of <variable> will be equal to <start> during the first iteration and will be incremented by 1 after each iteration until it's equal to <end>.
Example:
for i = 0 to 5 {
print(string(i) + " ")
}
// 0 1 2 3 4 5for i = 0 to 5 {
i = i + 1
print(string(i) + " ")
}
// 1 3 5 6