0
is it compulsory to use break after each case?
11 odpowiedzi
+ 4
if we dont use break, then all the following cases will get execute.
+ 2
No its not compulsory, had it been compulsory compiler would have been desined not to allow multiple cases without break. However care needs to be taken to put break after every cases. There can always be a case when we may not require break after all cases.
+ 1
switch executes everything from the matched case until a break is encountered
+ 1
it is compulsory because you do not use break after every case this will happen
suppose you have 3 cases case 1 ...case 3. like that if the user input a choice related to case when then of course as you know it will execute case 1 but remember you have not used break statement so after the execution of first case all the cases below that case 1will automatically be executed so it will generate a kind of logical or syntax error
0
yes
otherwise each n every case will be evaluated
0
yes in switch case we have to use break statement after each n every case
0
yes otherwise the all the cases following after "selected" case will be executed also you don't have to put break in the default case because it is the last case.
0
yes break is necessary otherwise it will execute all cases & then print all of them
0
yes break is necessary otherwise it will execute all cases &then print all of them
- 1
not compulsory at all.One should use #break according to the need.
- 1
yes it is compulsary to use break after each case because if we dont do so all the cases below the true case will also be executed