Control Flow

Control flow statements support looping, branching and decision making tests which select the blocks of code to execute.

Pollen control flow statements will be familar to programmers who know C or Java.

for (uint8 i = 0; i < 10; i++) {
  ...
}

These forms are also valid:

for (;;)                 { !-- an infinite loop --! }
for (j = 0; j < 10; j++) { !-- j has a default type of uint32 --!  }
while (x < 10) {
  x++
}
do {
  x++
} while (x < 10)

This form is also valid:

do {
  !-- 
      infinite loop. 
      note: terminating ';' is required. 
  --!
} while;

The decision making statements include if and switch.

if (x < 10) {
  x++
}
if (x < 10) { 
  x++
} else {
  x--
}
if (x < 10) { 
  x++
} elif (x < 20) {
  x++
} else {
  x = 0
}
switch (x) {

  case 0: 
    break

  case 1:
    break

  default:
    break

}

Control transfer statements in Pollen include break, continue, and return.

The continue statement skips the rest of the current iteration of a loop.

Break in a Loop Statement

The break statement exits any containing loops.

Break in a Switch Statement

The break statement exits the switch statement.

The return statement terminates the execution of the currently executing function and returns control to the caller.