Stenway Developer Network

Loops

While

Infinite loop

while true
  this.doSomething()
end

Shortened to:

while true : this.doSomething()

Continue

i int = 0
while i < 10
  i++
  if i == 3 : continue
  Console.log(i)
end

Break

i int = 0
while true
  i++
  if i == 10 : break
end

Until

i int = 0
until i == 10
  i++
end

Shortened to:

i int = 0
until i == 10 : i++

Foreach

foreach x int in array
  this.doSomething()
end

Shortened to:

foreach x int in array : this.doSomething()

For

for i int = 0 to array.size-1 by 1
  this.doSomething()
end

Shortened to:

for i int = 0 to array.size-1 by 1 : this.doSomething()

Break and continue

for i int = 0 to array.size-1 by 1
  if i == 4 : break
  else if i == 2 : continue
  this.doSomething()
end

Reverse:

for i int = array.size-1 to 0 by -1
  this.doSomething()
end

Do-Loop

While

i int = 0
do
  i++
loop while i < 10

Until

i int = 0
do
  i++
loop until i == 10

Infinite loop

do
  this.doSomething()
loop