The following Pascal program was given as a demonstration of FOR loops:
program looptest; var counter: integer; begin for counter := 1 to 100 do writeln(counter); end.
A for loop follows this format:
For ← <start value> TO/DOWNTO <end value> Do Begin ... ... End
A FOR loop is a definite loop (we know how many times it must loop).
A FOR loop loops to or down to a given value.
Pascal concepts:
:= is used for assignment (the same as ← in pseudocode)
The final END statement has a . after it instead of the usual ;
These exercises were given, and are due Tuesday March 15 2011:
Chapter 2 Exercise 6a, 6b, 6c, and 6e
Advertisement