BALDWIN GIRLS’ HIGH SCHOOL
COMPUTER SCIENCE - CHAPTER 6
DECISION CONTROL STRUCTURE
A. Fill in the blanks:
1. The selection statements cause the program control to
be transferred to a specific location depending upon the
outcome of the conditional expression.
2. The step value determines the increment or decrement
of the loop control variable unless the test condition
becomes false.
3. Java provides three basic looping control structures.
4. The for loop is called an entry controlled loop.
5. The do while first executes the block of statements and
then checks the condition.
6. The order in which statements are executed in a running
program is called the flow of control.
B. State true or false:
1. The break statement takes the flow of control out of the
switch statement. – True
2. To execute the while loop, the condition must be false in
the beginning. – False
3. Default is the first statement of the switch case. – False
4. While writing programs, the statements must be
indented properly for better readability. – True
5. The number of iteration refers to the number of times
the condition is met. – True
C. Application based questions:
1. Radhika is writing a program in Java to print her name
10 times. Suggest her the appropriate condition for the
same.
Ans: She can use the “For” or “While” loop.
2. Naina has written a program in which she has entered
one number. She wants to check whether the entered
number is divisible by 2 or not. Suggest her the
appropriate condition for the same.
Ans: She can use the “If” condition. Condition must be
“if num % 2 == 0”.
D. Multiple choice questions:
1. The a. if else is a logical situation where either of the two
actions are to be performed depending on certain condition.
2. Name the expression that is used to initialise a loop
variable. a. Initialization expression
3. The unusual execution of more than one case at a time is
termed as c. Fall through.
4. How many times will the following body of loop will
execute? c. 10 .
5. How many times will the following message be printed? a.
1.
6. If none of the case matches in SWITCH, the compiler
executes the statements written in the b. default case.
7. Which control structure is used when there is a
requirement to check multiple conditions in a program? b.
switch.
E. Answer the following:
1. Explain the use of IF control structure.
Ans. The statement containing if is referred to as bi-
directional branching, because it executes the block of
statements depending on the conditional expression. The
conditional expression consists of relational and logical
operators and must evaluate to either true or false. It can be
used in many ways in a program.
• If statement
• If else statement
• If else if ladder
2. What are the unique features of FOR loop?
Ans. For loop is used to repeat a task for finite number of
times. It performs a fixed number of iterations, which are
specified in a counter variable, which in turn keeps a track of
the number of iterations.
For loop is also called an Entry controlled loop, because the
body of the loop is executed only after the condition
evaluates to true. The loop will never be executed if the
condition is false in the beginning.
3. Explain the SWITCH statement with an example.
Ans. The switch statement is used when there is a
requirement to check multiple conditions in a program. It
provides an easy way to branch to different parts of the code
in a program based on the value of an expression. It is a
substitute for large series of if else if statements. This control
structure has a switch statement, which stores an expression.
It also has multiple cases where each case has a unique label
and a block of statements associated with it. The value of the
switch expression is compared to the labels of all the cases. If
the expression matches, the statement associated with that
case gets executed. If none of the case matches, the compiler
executes the statements written in the default case.
E.g.: A condition in which the birthstone of a person needs to
be displayed when the birth month is entered; for example,
when “October” is the case, the statement should be “Opal”.
4. What is the importance of BREAK and DEFAULT statements
in SWITCH?
Ans. The break statement takes the flow of control out of the
switch statement. Without the break statement, execution
would simply continue to the next case.
The default is the last statement of the switch case. It is an
optional statement. It executes only when the values stored
in switch expression does not match any case.
5. Give one difference between WHILE and DO WHILE loop.
Ans. The while loop checks the condition first, then executes
the statements. On the other hand, the do while loop first
executes the block of statements for once, and then checks
the condition.
**************************************************