Chapter 4
Chapter 4
Chapter 4
Conditional Statements in Java: Control Flow
with If, Else, and Switch-Case
01
Discussion
Agenda
02 Overview
If statements
If-Else statements
If-Else if statements
Nested If statements
Switch-case sttatements
CHAPTER 4
If
IF STATEMENT
Matches a single
Evaluates a single Evaluates a condition Evaluates multiple Evaluates multiple
Basic Structure variable against multiple
condition with an alternate block conditions in sequence conditions with nesting
values
Single condition with an Multiple conditions Conditions inside other Value matching (integer,
Condition Type Single condition
alternative path evaluated one by one conditions string, enum)
Thanks for
attending!
ITC02 - PROGRAMMING 1
SEATWORK:
True or False (10 items)
1. The if statement in Java allows you to execute a block of code only when a specific
condition is false.
2. In a switch-case statement, each case must end with a break statement to prevent fall-
through to the next case.
3. A nested if statement is when one if statement is placed inside another if or else block.
4. The if-else statement can only handle two possible outcomes.
5. The if-else-if statement is used to evaluate a condition with more than two possible
outcomes.
6. The switch-case statement can handle conditions with logical operators like && and ||.
7. The default block in a switch-case statement is mandatory and always required.
8. You can use any data type with the switch-case statement in Java, including int, char, and
String.
9. A switch-case statement is generally faster and more efficient than using multiple if-else
statements when checking the value of a single variable.
10. In an if-else statement, if the if condition is true, the else block is still executed.
SEATWORK:
ANSWERS:
1. False
2. True
3. True
4. True
5. True
6. False
7. False
8. True
9. True
10. False