Computer Science - Object Oriented Programming Using C++ - Discussion

Discussion Forum : Object Oriented Programming Using C++ - Section 1 (Q.No. 5)
5.
The use of the break statement in a switch statement is
optional
compulsory
not allowed. It gives an error message
to check an error
None of the above
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
26 comments Page 1 of 3.

Sharda said:   1 decade ago
How can it b optional? please let me know.

Sonu said:   1 decade ago
If you not write it, it will ok, but all statements from other cases also get executed.

Manisha said:   1 decade ago
Actually it's compulsory for proper output if we not written it then we not got proper output.

MRT said:   1 decade ago
I though this is compulsory. because we never use break option then. it execute all statement and if i use default option the it always execut and may be give wrong result ...!

Wasif said:   1 decade ago
Its not compulsory becouse when we want to prform same task for multiple cases in single itteration at that time there is no need use break statement for each case.

Eg:.

As + and - having same priority & * and / has same priority we can write.

Switch (operator).
Case +:.
Case -:.
Return 1;.
Break;.
Case *:.
Case /:.
Return 2;.
Break;.

Soujanya said:   1 decade ago
I think it is compulsory because if we use break statement we will get proper output otherwise all the statements get executed.

Diana said:   1 decade ago
If break is optional, then what is the purpose of using a switch statement?

Harikanth said:   1 decade ago
I did not get proper explanation can you suggest me in better way.

Prachi said:   1 decade ago
I think if we not write keyword after each case then all cases starting from first to last will execute, main thing is compiler not gives error, it is logical error.

Rahma said:   1 decade ago
I think if we do not use a break statement the code will be executed and compiler not gives error but the output will never be understandable by the user.


Post your comments here:

Your comments will be displayed after verification.