Loop
From GMpedia.org Wiki
(Redirected from Loops)
Loops in programming are instructions that are specified once but which may be carried out several times in succession[1].
Contents |
[edit] Types of Loops
Note that the types of loops above exist in different programming languages, and some loop types might be the same but correspond to slightly different actions depending on the programming language. Please also note that the syntax of the loop will be written in psuedo code and not a programming language.
[edit] for loop
Syntax:
for I=1 TO 6 ACTIONS NEXT I
- The for loop sets a variable to a certain value, then the variable is incremented by 1 and the actions are performed. The next I statement adds 1 to I and re-evaluates the statement, if I was less than 6, it repeats the actions, else, it stops.
[edit] while loop
Syntax:
WHILE (condition) statements END-WHILE
- The while loop repeats the statements until the condition becomes true, if it doesn't, the the loop is repeated for ever and the program crashes.
[edit] do-while
It is very similar to the while loop:
DO-WHILE (condition) statements END DO
- The do while is very similar to the while statement but with different words, it is used in different langauges.
[edit] do-until
Syntax:
DO statements UNTIL (condition)
- Unlike the do-while loop, the do-until loop repeats the statements as long as the condition is false. When then condition becomes true, the loop ends.
[edit] repeat-until
Very similar to the do-until loop, but used in different languages. Its syntax:
REPEAT statements UNTIL (condition)
- Similar to the do-until loop.
[edit] repeat
In other languages, the repeat loop has a different approach:
REPEAT(N) BEGIN actions END
- Unlike the repeat-until, the repeat loop repeats an action N times.

