if / then / else
Try it yourself →Executes code based on a condition.
Syntax
if condition then ... else ...;
Description
Do NOT put a semicolon BEFORE else. Use begin..end for multiple lines. Integer division is div, remainder is mod. Equality is =, inequality is <>.
Example
program H;
var score: integer;
begin
score := 75;
if score >= 50 then
writeln('Passed')
else
writeln('Failed');
end.Expected output
Passed
When to use?
Flow branching.
Common mistakes
- ⚠️ Do not put a ; before else: writeln('Gecti') else ...