For in Pascal
Pascal provides several looping constructs. Here are some basic types of loops.
To run the program, save it as forloops.pas
and use the Pascal compiler (e.g., Free Pascal):
Pascal’s looping constructs are slightly different from some other languages:
- The
while
loop is used for condition-based loops. - The
for
loop in Pascal is typically used for counting loops with a known range. - Pascal doesn’t have a direct equivalent to Go’s
for
without condition, but you can use while True
for an infinite loop. - The
repeat-until
loop is similar to a do-while
loop in other languages, always executing at least once. - Pascal uses
continue
to skip to the next iteration, similar to many other languages.
We’ll see some other loop forms later when we look at arrays, strings, and other data structures.