Break and Redo

The break and redo control statements allow manipulating the behaviour of both for and while loops.

Break

The break statement prematurely exits the loop.
var a = 0
while true do
{
  print a, " "
  a += 1
  if a == 10 do break
} 

The code above will output:
0 1 2 3 4 5 6 7 8 9 10

Redo

The redo statement skips further code in the current loop iteration and immediately starts a new one:

var a = 0
while a < 10 do
{
  a += 1
  if a < 5 do redo
  print a, " "
} 

The code above will output:
5 6 7 8 9

Last edited Mar 17, 2011 at 9:52 AM by impworks, version 1

Comments

No comments yet.