006 - Control Flow Statements Flashcards

1
Q

__________ break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code.

A

Control flow statements

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

__________ tells your program to execute a certain section of code only if a particular test evaluates to true.

A

The if-then statement

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

In an if-then statement, __________are optional, provided that the “then” clause contains only one statement:

A

the opening and closing braces

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

__________ provides a secondary path of execution when an “if” clause evaluates to false.

A

The if-then-else statement

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

__________ can have a number of possible execution paths.

A

the switch statement

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

A switch works with the __________ primitive data types

A

byte, short, char, and int

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

A switch works with __________ types, the _________ class, and a few special classes that wrap certain primitive types: __________.

A

enumerated
String
Character, Byte, Short, and Integer

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

The body of a switch statement is known as _________.

A

a switch block

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

A statement in the switch block can be labeled with _________.

A

one or more case or default labels

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

The switch statement evaluates its expression, then executes all statements that __________.

A

follow the matching case label

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

Deciding whether to use if-then-else statements or a switch statement is based on __________ and __________.

A

readability

the expression that the statement is testing

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

An if-then-else statement can test expressions based on __________ or __________, whereas a switch statement tests expressions based __________, __________, or __________.

A

ranges of values or conditions

only on a single integer,
enumerated value or
String object.

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

Each __________ terminates the enclosing switch statement.

A

break statement

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

The break statements are necessary because without them, __________.

A

statements in switch blocks fall through

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

All statements after the matching case label are executed in sequence, regardless of the expression of subsequent case labels, until a __________.

A

break statement is encountered

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

Technically, a break in __________ is not required because flow falls out of the switch statement.

A

the final case section

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

The __________handles all values that are not explicitly handled by one of the case sections.

A

default section

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

In Java SE 7 and later, you can use __________ in the switch statement’s expression.

A

a String object

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

The __________continually executes a block of statements while a part

A

while statement

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

The while statement evaluates __________, which must return __________.

A

An expression

a boolean value

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

If __________ in a while control flow evaluates to true, the while statement executes the statement(s) in the while block.

A

the expression

22
Q

The while statement continues testing the expression and executing its block until __________.

A

the expression evaluates to false

23
Q

The difference between do-while and while is that __________ evaluates its expression at the bottom of the loop instead of the top.

24
Q

the statements within the __________ are always executed at least once

25
The __________ provides a compact way to iterate over a range of values.
for statement
26
Programmers often refer to a __________ as the "for loop"
For statement
27
In a for statement, the __________ initializes the loop; it's executed once, as the loop begins.
initialization expression
28
When the __________ evaluates to __________, the loop terminates.
termination expression | false
29
The __________ is invoked after each iteration through the loop
increment expression
30
In an increment expression, it is perfectly acceptable to _________ or __________ a value.
increment or decrement
31
The names __________, __________, and __________ are often used to control for loops
i, j and k
32
declaring _________ within the initialization expression limits their life span and reduces errors
The initialization variable
33
The for statement also has another form designed for iteration through __________ and __________ This form is sometimes referred to as __________
Collections and arrays the enhanced for statement
34
__________ can be used to make your loops more compact and easy to read. To demonstrate
the enhanced for statement
35
The break statement has two forms: __________ and __________
labeled and unlabeled
36
You can also use an unlabeled break in a __________, to terminate a __________, __________, or __________ .
switch statement for, while or do-while loop
37
An unlabeled break statement terminates the __________ switch, for, while, or do-while statement, but a labeled break terminates __________.
innermost an outer statement
38
The __________ skips the current iteration of a for, while , or do-while loop.
continue statement
39
The __________ skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop
unlabeled continue statement
40
A __________ skips the current iteration of an outer loop marked with the given label.
labeled continue statement
41
The return statement __________, and control flow returns to __________.
exits from the current method where the method was invoked
42
The return statement has two forms: __________, and __________.
one that returns a value one that doesn't
43
To return a value with the return statement, simply put the value (or an expression that calculates the value) __________.
after the return keyword return ++count;
44
The most basic control flow statement supported by the Java programming language is the ___ statement.
If-then
45
The ___ statement allows for any number of possible execution paths.
Switch
46
The ___ statement is similar to the while statement, but evaluates its expression at the ___ of the loop.
do-while
47
How do you write an infinite loop using the for statement?
for(;;){ | }
48
How do you write an infinite loop using the while statement?
while(true){ }
49
Consider the following code snippet. if (aNumber >= 0) if (aNumber == 0) System.out.println("first string"); else System.out.println("second string"); System.out.println("third string"); What output do you think the code will produce if aNumber is 3?
Second string | Third string
50
Consider the following code snippet. if (aNumber >= 0) if (aNumber == 0) System.out.println("first string"); else System.out.println("second string"); System.out.println("third string"); Using only spaces and line breaks, reformat the code snippet to make the control flow easier to understand. Use braces, { and }, to further clarify the code.
``` if (aNumber >= 0) { if (aNumber == 0) { System.out.println( "first string"); } } else { System.out.println( "second string"); } System.out.println("third string"); ```