You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I should be able to loop, either over a range of data or until a certain condition is no longer true.
var a = 0
while a < 3 {
a = a + 1
}
a // 2
var greeting = "He"
for ch in ["l", "l", "o"] {
greeting = greeting + ch
}
// This would also produce the same effect, since strings should be considered iterable:
for ch in "llo" { .. }
// Also, to obtain the index there is an optional second parameter
for ch, idx in ["l", "l", "o"] {
println("Index: " + idx)
greeting = greeting + ch
}
// The `range` builtin can also be used to iterate over ranges
var sum = 0
for i in range(0, 10) {
sum = sum + i
}
Loops can also be infinite-loops, meaning that they will continue to loop until a break keyword is met
var a = 0
while a < 3 {
a = a - 1 // a will always be less than 3, so infinite loop occurs
if a == -100 {
break
}
}
The text was updated successfully, but these errors were encountered:
I should be able to loop, either over a range of data or until a certain condition is no longer true.
Loops can also be infinite-loops, meaning that they will continue to loop until a
break
keyword is metThe text was updated successfully, but these errors were encountered: