Control Structures Flashcards

(26 cards)

1
Q

____ are used to control the execution flow of the program. The execution order of the
program is based on the supplied data values and the conditional logic.

A

Control Statements

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

What are the following types of control statements that Java supports ?

A

• Selection
• Repition
• Branching

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

____ are decision making statements that include if, if-else and switch statements.

A

Selection Statements

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

The if decision construct is followed by a logical expression wherein data is compared, and a decision is
made depending on the comparison result.

A

If statement

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

It is an extension of the if statement that provides an alternative action when the if statement results in a
false outcome.

A

If-else Statement

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

This statement successfully lists the value of a variable or an expression
against a list of byte, short, char, or int primitive data types only.

A

Switch Statement

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

The switch keyword is followed by the _____ in _____

A

The switch keyword is followed by the variable in parenthesis

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

What are the Switch statement rules ?

A

• The default label must always be the last option in the switch construct if used

• The case expressions can be of either numeric or character data type

• The case constants in the switch statement cannot have the same value

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

What is the output of this program ?
int day=5;
switch (day)
{
case 1:
System.out.println(“Monday”);
break;
case 2:
System.out.println(“Tuesday”);
break;
case 3:
System.out.println(“Wednesday”);
break;
case 4:
System.out.println(“Thursday”);
break;
case 5:
System.out.println(“Friday”);
break;
case 6:
System.out.println(“Saturday”);
break;
case 7:
System.out.println(“Sunday”);
break;
default:
System.out.println(“Invalid entry”);
break;

A

Friday

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

_____ are looping statements that include while, do-while, and for statements.

A

Repetition Statements

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

A ____ causes a section of a program to be repeated based on the specified number of times. This repetition
continues while the condition set for it remains true. Otherwise, the loop ends and the control is passed to
the statement following the loop construct.

A

Loop

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

It is a looping construct that continues until the evaluating condition becomes false. The evaluating condition
must be a logical expression and must return a true or a false value.

A

While Loop Statement

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

The variable checked in the Boolean
expression is called the _____ .

A

Loop control variable

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

It lists the conditions after the statements to be executed. This statement can
be considered a post-test loop statement. First, the do block statement is executed, and then, the condition
given in the while statement is checked.

A

Do-while loop statement

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

the ___ is used when iterations are known in
advance. This looping statement can be used when determining the square of each of the first ten numbers.

A

For loop Statement

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

The for statement consists of the ___ keyword followed by parentheses containing three expressions
separated by a semicolon.

17
Q

The for statement consists of the for keyword followed by parentheses containing three expressions
separated by a semicolon. What are those ?

A

Initialization – gives the loop variable an initial value. This expression is executed only once when
the control is passed to the loop for the first time.
• Test – executes the condition each time. The control passes to the start of the loop. The loop’s body
is executed only after the condition has been checked. If the condition is true, the loop is executed.
Otherwise, the control is passed to the following statement.
• Increment/Decrement – this expression is always executed when the control returns to the
beginning of the loop.

18
Q

It gives the loop variable an initial value. This expression is executed only once when
the control is passed to the loop for the first time.

A

Initialization

19
Q

executes the condition each time. The control passes to the start of the loop. The loop’s body
is executed only after the condition has been checked. If the condition is true, the loop is executed.
Otherwise, the control is passed to the following statement.

20
Q

this expression is always executed when the control returns to the
beginning of the loop.

A

Increment/Decrement

21
Q

Determine which is the loop variable, initialization, increment and test expression.

for (invar=o; invar<=10; invar++)

A

invar is the loop variable
invar= 0 is the initialization expression
invar<10 is the test expression
invar++ is the increment expression

22
Q

It is a branching statement that can be labeled or unlabeled.

A

Break Statement

23
Q

A ___ loop is a
loop that exists within another loop.

24
Q

A break Syntax, which breaks the outermost loop in the series of nested loops.

25
It is used in looping statements such as while, do-while, and for to skip the current iteration of the loop and resume to the next iteration.
Continue Statement
26
It transfers the control to the caller of the method. It is used to return a value to the caller method and terminates the execution of the method.
Return Statement