From Clomosy Docs
Conditional statement structures require the programmer to specify one or more conditions that will be evaluated or tested by the program, one or more statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.
Statement | Description |
---|---|
if - then statement | An if - then statement consists of a boolean expression followed by one or more statements. |
If then-else statement | An if - then statement can be followed by an optional else statement, which executes when the boolean expression is false. |
If then-else if statement | It is a structure used to sequentially check multiple conditions. |
nested if statements | You can use one if or else if statement inside another if or else if statement(s). |
case statement | A case statement allows a variable to be tested for equality against a list of values. |
case - else statement | It is similar to the if-then-else statement. Here, an else term follows the case statement. |
if-else statement example
var I:Integer; { I =3; if (I <> 0) { ShowMessage('The number is not equal to the number 0.'); } }
If-then-else statement example
var age: Integer; { age = 28; if (age >= 18) ShowMessage('You are an adult.') else ShowMessage('You are a minor.'); }
If then-else if statements example
var score: Integer; { score = 85; if (score >= 90) ShowMessage('Grade: A') else if (score >= 80) ShowMessage('Grade: B') else if (score >= 70) ShowMessage('Grade: C') else if (score >= 60) ShowMessage('Grade: D') else ShowMessage('Grade: F'); }
nested if statements example
var age: Integer; hasPermission: Boolean; { age = 20; hasPermission = True; if (age >= 18) { if (hasPermission) ShowMessage('Access granted.') else ShowMessage('Access denied. Permission required.'); } else ShowMessage('You are a minor. Access denied.'); }
case statement example
var grade: char; { grade = 'F'; case grade of { 'A': ShowMessage('Excellent!'); 'B': ShowMessage('Good job!'); 'C': ShowMessage('Fair!'); 'D': ShowMessage('Needs improvement!'); 'F': ShowMessage('Failed!'); } }
case - else statement example
var day: integer; { day = 10; case day of { 1: ShowMessage('Monday'); 2: ShowMessage('Tuesday'); 3: ShowMessage('Wednesday'); 4: ShowMessage('Thursday'); 5: ShowMessage('Friday'); 6: ShowMessage('Saturday'); 7: ShowMessage('Sunday'); else ShowMessage('Invalid day!'); } }