WHILE LOOP
 

THE WHILE LOOP
The while loop is similar to the for loop shown earlier, in that it allows a {group of} program statement(s) to be executed a number of times. The structure of the while statement is,

	while   condition_is_true  do
begin
program statement;
program statement
end; {semi-colon depends upon next keyword}
or, if only a single program statement is to be executed,
	while   condition_is_true   do   program statement;

The program statement(s) are executed when the condition evaluates as true. Somewhere inside the loop the value of the variable which is controlling the loop (ie, being tested in the condition) must change so that the loop can finally exit.




SELF TEST
Determine the output of the following program

program WHILE_DEMO (output);
const PI = 3.14;
var XL, Frequency, Inductance : real
begin
Inductance := 1.0;
Frequency := 100.00;
while Frequency < 1000.00 do
begin
XL := 2 * PI * Frequency * Inductance;
writeln('XL at ',Frequency:4:0,' hertz = ', XL:8:2 );
Frequency := Frequency + 100.00
end
end.
 
Self test .. Output of program WHILE_DEMO is..
XL at 100 hertz = ..........
XL at 200 hertz = ..........
.............................
XL at 1000 hertz = ..........

(c) Shilpa Sayura Foundation 2006-2017