Answer by fpierrat for switch-case statement without break
I've seen in many comments and answers that it's a bad practice to omit break lines. I personally find it very useful in some cases. Let's just take a very simple example. It's probably not the best...
View ArticleAnswer by Adham Gamal for switch-case statement without break
switch (option}{ case 1: do A; case 2: do B; case 2: do C; break; default: do C; } if your option is 1 it executes everything til it finds the break keyword... that mean break end the excution of the...
View ArticleAnswer by Craig Mosey for switch-case statement without break
The break acts like a "GOTO" command, or , what might be a better example is , its like when using the "return" on a "void" function. So since its a the end, it makes no difference whether its there or...
View ArticleAnswer by Khatri for switch-case statement without break
If you don't include break in any of case then all the case below will be executed and until it sees break. And if you don't include break in default then it will cause no effect as there are not any...
View ArticleAnswer by Shoe for switch-case statement without break
You execute everything starting from the selected case up until you see a break or the switch statement ends. So it might be that only C is executed, or B and then C, or A and B and C, but never A and C
View Articleswitch-case statement without break
According to this book I am reading: Q What happens if I omit a break in a switch-case statement? A The break statement enables program execution to exit the switch construct. Without it, execution...
View ArticleAnswer by soch guru for switch-case statement without break
The key is execution control is transferred to the statement for the matching case. E.g.1. switch(x) { 2. case 1: 3. do_step1; 4. case 2: 5. do_step2; 6. default: 7. do_default; 8. } Treat lines 2, 4,...
View ArticleAnswer by Thiago Navarro for switch-case statement without break
Try yourself - Run the code using ideone available here.#include <stdio.h>void doA(int *i){ printf("doA i = %d\n", *i); *i = 3;}void doB(int *i){ printf("doB i = %d\n", *i); *i = 4;}void doC(int...
View ArticleAnswer by Jefke MénenHoekaf for switch-case statement without break
Without break statements, each time a match occurs in the switch, the statements for that case and SUBSEQUENT CASES execute until a break statement or the end of the switch is encountered.
View Article