II-84 Programming Concepts
We can also use break statements in the nested loops. If we use break statement in the innermost
loop, then the control of the program is terminated only from the innermost loop.
21. Why the break statement is essential in the switch statement?
Ans: In switch statement, we find a number of cases written one after another. When the case
variable matches with any of the cases, the control passes to that case and execution begins from the
statement following to that case. If we do not write the break statement after each case, the control
starts executing all the cases written after the case that has been matched; therefore, to avoid this situation,
we have to write break statement after each case.
22. Is it permissible to use break statement outside the loop?
Ans: One should not use break statement outside the loop. It is used only exiting from the loop.
Therefore, question does not arises to use outside the loop.
23. Which other functions or keywords can be used in place of the break statement?
Ans: The break statement is used to pass the control out of the loop. We can use the goto statement
to pass the control outside the loop by writing a label at the end of the loop statement.
24. Is it possible to use the else statement in place of a default statement or vice versa?
Ans: The else statement can be used with only the if statement; therefore, we cannot use it at the
place of a default statement.
Moreover, the if statement cannot be paired with any statement other than the else statement;
therefore, we cannot use a default statement in place of the else statement.
25. Can we put default statement anywhere in the switch case structure?
Ans: Yes, we can put default statement anywhere in the switch statement, because in switch
statement the sequence of cases does not matter in the execution of the statement.
26. What are the limitations of the switch case statement?
Ans: The switch case statement can check only for equality; we cannot have any logical expres-
sion in case statement, also we can use only integer or character value, the floating-point values are
avoided in case statements.
27. What is a sequential execution?
Ans: When the control is passed line by line, one statement after another in the sequence without
any jump, or looping without skipping any of the statements in the sequence, such an execution is called
sequential execution.
28. What is the transfer of control?
Ans: The transfer of control means changing the statement that is going to execute next in the sequence.
29. Write short note on goto statement?
Ans: This statement does not require any condition. This is unconditional control jump. This state-
ment passes control anywhere in the program, i.e., control is transferred to another part of the program
without testing any condition. User has to define goto statement as follows:
goto label;
where the label name must start with any character.
M05_ITL-ESL4791_02_SE_C05.indd 84 12/22/2012 4:58:54 PM