Lesson 3 - Flow of Control Flashcards
What is flow of control in Java?
It refers to how statements are executed using branching and looping mechanisms
What are the branching statements in Java?
A: if, if-else, switch
What is a boolean expression?
An expression that evaluates to true or false?
What does the == operator do with strings?
It checks if two string objects are stored in the same memory location, not their values.
How should string equality be checked?
Using .equals() or .equalsIgnoreCase()
What happens in an if-else statement?
The program executes one block if the condition is true, another if it’s false
What is a multiway if-else?
A chain of if-else if-else statements.
How does a switch statement work?
It selects a block to execute based on a var
What must the switch statement’s controlling expression evaluate to?
A: char, int, short, or byte
What happens if a break is omitted in a switch case?
Execution “falls through” to the next case
What are the three types of loops in Java?
While, do-while, for
How does a while loop work?
It checks the condition first; if true, it executes the body.
How does a do-while loop work?
It executes the body once before checking the condition
What are the three components of a for loop?
Initialization, condition, update
What is an infinite loop?
A loop where the condition never becomes false.
What is the conditional (ternary) operator?
condition ? value_if_true : value_if_false
What is short-circuit evalutation?
If && encounters false or || encounters true, evaluation stops
What is an assertion in Java?
A statement that verifies a condition using assert condition;
What is System.exit(0); used for?
To terminate a program
What are common loop errors?
Infinite loops, off-by-one errors.