repeat loop in pascal
In Pascal, you can create a repeat loop using the repeat
and until
keywords. The code inside the loop will be executed repeatedly until a certain condition is met. Here's the syntax:
repeat
// code to be executed
until condition;
The condition
is a Boolean expression that determines when the loop should stop. The loop will continue executing the code inside until the condition evaluates to true
.
Here's an example of a repeat loop that prints the numbers from 1 to 5:
program RepeatLoopExample;
var
i: Integer;
begin
i := 1;
repeat
writeln(i);
i := i + 1;
until i > 5;
end.
This program will output:
1
2
3
4
5
In this example, the loop starts with i
initialized to 1. The code inside the loop prints the value of i
and increments it by 1. The loop continues until i
is greater than 5.
Please let me know if you need further assistance!