Introduction to the Pascal Programming Language
© 1998 by Dr. Thomas W. MacFarland -- All Rights Reserved
Instructions: Review the following program and see if you can predict the outcome by completing a "pencil trace" of the code. Program output is provided at the end of this page. Compiler: The program was prepared using Standard Pascal on a UNIX-based host computer.
% cat PASCAL/intro_pencil-13.p
{ Introduction to the Pascal Programming Language
Dr. Thomas W. MacFarland
intro_pencil-13.p
}
{ The purpose of this program is to:
1. Demonstrate the structure of a repeat/until loop.
2. Demonstrate a counter variable that increments in
value with each iteration.
3. Demonstrate a counter variable that decrements in
value with each iteration.
}
program Demonstrate_a_Repeat_Until_Loop;
var A, B : integer;
begin
A := 5;
repeat
write(' A = ', A :4);
A := A + 3;
until A >= 15; writeln;
B := 9;
repeat
write(' B = ', B :4);
B := B - 2;
until B <= -2; writeln;
end. { intro_pencil-13.p }
% pc PASCAL/intro_pencil-13.p
% a.out
A = 5 A = 8 A = 11 A = 14
B = 9 B = 7 B = 5 B = 3 B = 1 B = -1