Program Control Flashcards

1
Q

Selection statements

A

If and Switch

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

Iteration Statements

A

For, While, Do-While Loops

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

Jump Statements

A

Break, Continue & Return

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

If Statement Syntax

A
if (condition)
{
      ...
}
else
{
    ...
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

If-Else If-Else Syntax

A
If (condition)
{...}
Else If (condition)
{...}
Else
{...}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Switch Statement Uses

A

Value of an expression is tested against a list of scenarios. When a match is found, that statement sequence is executed.

Enables a program to select among alternatives.

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

Switch Statement Syntax

A
Switch(expression) {
  case constant1:
      Statement sequence
      break;
   case constant2:
      statement sequence
      break;
   default:
      statement sequence
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Valid types for switch expressions

A

byte, short, int, char, String

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

Is the default switch statement required?

A

No, it is optional. No action takes place if all matches fail.

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

Can you nest Switch Statements?

A

Yes

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

For Loop Uses

A

Performing a known number of iterations

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

For Loop Syntax

A

for (initialization; Boolean condition; iteration)
{
statement sequence
}

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

While Loop Uses

A

An unknown number of iterations

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

While Loop Syntax

A

While (condition)

statement;

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

Do-While Loop Uses

A

When at least one iteration is necessary in an unknown number of iterations

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

Do-While Loop Syntax

A

do {
statements;
}
while (condition);

17
Q

Purpose of Break in a Loop

A

Force an immediate exit & bypass any remaining code.

18
Q

Where does program control resume after a break?

A

The next statement following the Loop.

19
Q

Where does program control resume after a break in an inner loop?

A

The next line in the outer loop.

20
Q

Labeled Break

A

Expanded break for exiting from a deeply nested set of loops.

Syntax: break label;

The label is the name identifying a block of code.
To name a block: label: {block of code}

21
Q

Continue

A

Bypass loop control & force an early iteration

Rare.