Two Types of Loops

Home, Up: Loops

 

Hypatia knows two different types of loops:

- DO loops (and the closely related REPEAT loops)

- GOTO loops

For many tasks you can use either, but they work very differently.

 

DO loops (and REPEAT loops which you will probably use less often, if ever) are elaborate tools that come with a number of commands, parameters and pseudo constants.

GOTO loops (which were already mentioned on page GOTO and Labels in chapter "Scripts") on the other hand only know two elements: labels and the command GOTO.

 

DO (and REPEAT) loops can loop single calculation lines, but more importantly they can loop scripts. They cannot be used within a script, though, and they cannot be nested.

GOTO loops can only be used within a script. A script can contain two or more GOTO loops which can follow each other, but GOTO loops can also be nested.

DO and REPEAT loops can end when a condition is met (there are several ways this can be done), or after a given number of passes. GOTO loops must always be exited by a command in the script.

DO and REPEAT loops are very Hypatia-specific constructs -- if you have experience with programming languages, GOTO loops will feel more familiar to you.

 

And, even though this will only be relevant for rather complex tasks, you can combine DO (or REPEAT) and GOTO loops. A script called by a DO (or REPEAT) loop can contain one or more GOTO loops.

In this chapter we will first discuss DO loops, then the closely related REPEAT loops, and conclude with GOTO loops.

 

Home, Up: Loops, Next: The DO Loop Command