![]() |
VOOZH | about |
Conditional statements are used to control the flow of execution in a program based on specific conditions. They allow programs to execute different blocks of code depending on whether a condition evaluates to True or False.
If statement is used to execute a block of code only when a specified condition evaluates to True.
Eligible to vote.
Short-hand if is used to write if statements in a single line. It is useful when only one statement needs to be executed.
Eligible to Vote.
If Else statement is used to execute one block of code when the condition is True and another block when the condition is False.
Travel for free.
elif statement is used to check multiple conditions in a program. It executes a block of code when its condition evaluates to True after previous conditions evaluate to False.
Young adult.
Explanation: Since age is 25, it skips the first two conditions (age <= 12 and age <= 19) and the third condition (age <= 35) is True, so it prints "Young adult.".
Nested if-else statement is an if-else statement placed inside another if or else block. It is used to check conditions within another condition.
30% senior discount!
Conditional Expression (Ternary Operator) is a short way to write an if-else statement in a single line. It is used when choosing between two values based on a condition.
Adult
Explanation: If age >= 18 is True, status is assigned "Adult". Otherwise, status is assigned "Minor".
Match-Case statement is used to compare a value against multiple patterns and execute the matching block of code. It is similar to the switch-case statement available in other programming languages.
Output
Two or Three