Loops

while loop

while condition {
   body
}

Parentheses in condition are not necessary.

i = 0
while i < 5 {
  print i++
}

// or

i = 0
while (i < 5) {
  print i++
}

do-while loop

do {
   body
} while condition

Parentheses in condition are not necessary.

i = 0
do {
  print i++
} while i < 5

// or

i = 0
do {
  print i++
} while (i < 5)

for loop

for initializing, condition, increment {
   body
}

for (initializing, condition, increment) {
   body
}
for i = 0, i < 5, i++
  print i++

// or

for (i = 0, i < 5, i++) {
  print i++
}

foreach loop

Iterates elements of an array or map.

for value : array {
   body
}

for key, value : map {
   body
}

for (value : array) {
   тело цикла
}

for (key, value : map) {
   body
}
arr = [1, 2, 3, 4]
for v : arr {
  println v
}

map = {"key1": 1, "key2": 2}
for key, value : map
  println key + " = " value
}

results matching ""

    No results matching ""