for
loop when you know the number of iterations needed. It is ideal for iterating over a range of values.for i := 1 to 10 do begin
// Code to execute
end;
While Loop: Use the while
loop when you want to execute a block of code as long as a condition is true. This loop might not execute at all if the condition is false initially.
while i <= 10 do begin
// Code to execute
i := i + 1;
end;
Repeat-Until Loop: Use the repeat-until
loop when you want to execute a block of code at least once and then repeat as long as a condition is true.
repeat
// Code to execute
i := i + 1;
until i > 10;
If-Then-Else: Use the if-then-else
statement to execute code based on a condition. You can include an else
block to handle the case when the condition is false.
if x = y then
// Code to execute if the condition is true
else
// Code to execute if the condition is false
case x of
1: // Code for case 1
2: // Code for case 2
else
// Code for all other cases
end;
regards
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,522 Super User 2024 Season 2
Martin Dráb 228,441 Most Valuable Professional
nmaenpaa 101,148