if / then / else
Try it yourself →Executes code based on a condition.
Syntax
if condition then ... else ...;
Description
NO semicolon is placed BEFORE else. begin..end is used for multiple lines. Equality is =, inequality is <>.
Example
program H;
{$MODE DELPHI}
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 ; before else: writeln('Gecti') else ... (no ; on the first line).