1 2 3 4 5 6 7 8 9
All Flashcards
What are the basic steps for executing an if-else statement?
- Evaluate the condition. 2. If true, execute the 'if' block. 3. If false, execute the 'else' block.
Define 'if-else statement'.
A control structure that executes one block of code if a condition is true, and another block if the condition is false.
What is a 'condition' in an if-else statement?
A boolean expression that determines which block of code is executed.
Define 'code block'.
A group of zero or more statements enclosed in curly braces {}
.
Define 'syntax'.
The set of rules that defines the structure of a programming language.
What is the purpose of an 'else' statement?
To provide an alternative block of code to execute when the 'if' condition is false.
Why are curly braces {}
important in if-else statements?
They define the code blocks for both the 'if' and 'else' parts, ensuring correct execution.
Explain the flow of execution in an if-else statement.
The condition is evaluated. If true, the 'if' block executes. If false, the 'else' block executes.
Why is indentation important in if-else statements?
Improves code readability and helps visually identify code blocks.