The repeat-statement is one of Magma's iterative statements. It has the syntax:
repeat STATEMENT; ... STATEMENT; until CONDITION;
To execute this statement, Magma initially executes all the statements between `repeat' and `until'. Then it evaluates the condition, which must be a Boolean expression. If it is false, then Magma executes the statements again. After that, Magma evaluates the condition, and if it is false, the statements are executed another time. This process continues until the condition is true.
If you are entering a repeat-statement into Magma interactively, you will normally be given a special prompt
repeat>
until you type until CONDITION; .
The statement break; within a repeat-loop causes the loop to stop immediately. Execution proceeds from the statement immediately after the loop.
The statement continue; within a repeat-loop causes Magma to omit the rest of the block of statements and to go to the bottom of the loop to test the condition again. If the condition is true, execution proceeds from the beginning of the loop statements.
// a run of the (3n+1) problem > n := Random(2, 100); > repeat repeat> print n; repeat> if IsEven(n) then repeat|if> n div:= 2; repeat|if> else repeat|if> n := 3*n+1; repeat|if> end if; repeat> until n eq 1; 13 40 20 10 5 16 8 4 2
[Next] [Prev] [Right] [Left] [Up] [Index] [Root]