Jump to content

[PASCAL] While loop


CouldnoT
 Share

Recommended Posts

While loop

 

In the while , the condition is checked first before entering the loop, but repeat enters the loop first then it checks the condition.

That means repeat always executes its statement(s) once at least, but while loop could prevent entering the first cycle if the condition returns False from the beginning.

 

while loop needs begin end if there are multiple statements that need to be executed in a loop,

but repeat does not need begin end, its block (repeated statements) starts from the repeat keyword to the until keyword.

 

 

Example :

 

var
 Num: Integer;
begin
 Write('Input a number: ');
 Readln(Num);
 while Num > 0 do
 begin
 Write('Clanin is noob');
 num:= 0;
 end;
 Write('Press enter key to close');
 Readln;
end.

 

The while loop has no loop counter and it will spam the order between begin and end forever, and for that reason we have used the set num to 0 to stop the loop.

Edited by CouldnoT
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.