0

switch statement

alpha is 5 { case 1 case 2: alpha = 2 + alpha; break; case 4: alpha++; case 5: alpha = alpha * 2; case 6: alpha = alpha + 5; break; default alpha - -; } My question is what happens at ‘case 4’. Does it not suppose to increament if my lecture says the answer is 15 not 17. Or he made some mistakes

4th Oct 2017, 9:02 PM
johnson
johnson - avatar
2 Respuestas
0
nothing till it hits a match , so nothing at 4 , then first it jumps to case 5 and alpha = 5*2=10, since no break it goes to case 6 too alpha = 10+5= 15, then we have break so it comes out hence 15
4th Oct 2017, 9:16 PM
Morpheus
Morpheus - avatar
0
Thank you
12th May 2018, 7:11 PM
johnson
johnson - avatar