Chapter 5 - Flow Control, Exceptions and Assertions Flashcards

1
Q

The only legal expression in an if statement is a

A

boolean expression

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

what out for boolean assignments

A

(=) that can be mistaken for a boolean equality test (==)

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

Curly braces are optional for if blocks

A

that have only one conditional statement. Watch out for misleading indentations.

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

switch statements can evaluate only to

A

enums, byte, short, int and char data types.

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

The case statement must be literal or a final variable

A

you cannot have a case that includes a non-final variable, or range of values

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

the default keyword should be used in a switch statement if

A

you want to run some code when none of the case values match the conditional code

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

The default block can be located anywhere in the switch block

A

if default block does NOT have a break statement, execution will continue to the next line… FALL THROUGH

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

A basic for statement has 3 parts

A

declaration and or initialization, boolean evaluation, and the iteration expression.

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

If a variable is incremented or evaluated within a basic for loop

A

it must be declared before the loop, or within the for loop declaration

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

A variable declared (not just initialized) within the basic for loop declaration

A

cannot be accessed outside the for loop

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

An enhanced for statement has 2 parts

A

declaration and expression. Used only to loop through arrays or collections

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

With an enhanced for

A

the declaration block is the block variable, whose type is compatible with the elements of the array or collection

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

You cannot use a number or anything that does not evaluate to a boolean

A

as a condition for an if statement or looping construct.

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

The do loop

A

will enter the body of the loop at least once, even if the test condition is not met

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