____ 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.
Control Statements
What are the following types of control statements that Java supports ?
• Selection
• Repition
• Branching
____ are decision making statements that include if, if-else and switch statements.
Selection Statements
The if decision construct is followed by a logical expression wherein data is compared, and a decision is
made depending on the comparison result.
If statement
It is an extension of the if statement that provides an alternative action when the if statement results in a
false outcome.
If-else Statement
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.
Switch Statement
The switch keyword is followed by the _____ in _____
The switch keyword is followed by the variable in parenthesis
What are the Switch statement rules ?
• 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
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;
Friday
_____ are looping statements that include while, do-while, and for statements.
Repetition Statements
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.
Loop
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.
While Loop Statement
The variable checked in the Boolean
expression is called the _____ .
Loop control variable
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.
Do-while loop statement
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.
For loop Statement
The for statement consists of the ___ keyword followed by parentheses containing three expressions
separated by a semicolon.
for
The for statement consists of the for keyword followed by parentheses containing three expressions
separated by a semicolon. What are those ?
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.
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.
Initialization
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.
Test
this expression is always executed when the control returns to the
beginning of the loop.
Increment/Decrement
Determine which is the loop variable, initialization, increment and test expression.
for (invar=o; invar<=10; invar++)
invar is the loop variable
invar= 0 is the initialization expression
invar<10 is the test expression
invar++ is the increment expression
It is a branching statement that can be labeled or unlabeled.
Break Statement
A ___ loop is a
loop that exists within another loop.
Nested
A break Syntax, which breaks the outermost loop in the series of nested loops.
break label;