Lesson 3 - Flow of Control Flashcards

1
Q

What is flow of control in Java?

A

It refers to how statements are executed using branching and looping mechanisms

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the branching statements in Java?

A

A: if, if-else, switch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a boolean expression?

A

An expression that evaluates to true or false?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the == operator do with strings?

A

It checks if two string objects are stored in the same memory location, not their values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How should string equality be checked?

A

Using .equals() or .equalsIgnoreCase()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What happens in an if-else statement?

A

The program executes one block if the condition is true, another if it’s false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a multiway if-else?

A

A chain of if-else if-else statements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does a switch statement work?

A

It selects a block to execute based on a var

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What must the switch statement’s controlling expression evaluate to?

A

A: char, int, short, or byte

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens if a break is omitted in a switch case?

A

Execution “falls through” to the next case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the three types of loops in Java?

A

While, do-while, for

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does a while loop work?

A

It checks the condition first; if true, it executes the body.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does a do-while loop work?

A

It executes the body once before checking the condition

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the three components of a for loop?

A

Initialization, condition, update

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is an infinite loop?

A

A loop where the condition never becomes false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the conditional (ternary) operator?

A

condition ? value_if_true : value_if_false

17
Q

What is short-circuit evalutation?

A

If && encounters false or || encounters true, evaluation stops

18
Q

What is an assertion in Java?

A

A statement that verifies a condition using assert condition;

19
Q

What is System.exit(0); used for?

A

To terminate a program

20
Q

What are common loop errors?

A

Infinite loops, off-by-one errors.