Previous Up Next

10.3.6  Breaking out a loop

If your program is running a loop and you want it to exit the loop without finishing it, you can use the break command. For example, you can define a program

  testbreak(a,b) := {
  local r;
  while (true) {
    if (b == 0) {break;}
    r := irem(a,b);
    a := b;
    b := r;
  }
  return a;
  }

If you then enter

testbreak(4,0)

it will return

4

since the while loop is interrupted when b is 0 and a is 4.


Previous Up Next