Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.   int mode = 0;
  5.   int doipass = 1; // changed between tests
  6.   for (mode = 0; mode < 3; mode++) {
  7.     printf("We're in mode %i and the if will %sfail\n", mode, doipass?"not ":"");
  8.     switch (mode) {
  9.       case 0: if (doipass) {
  10.       case 1:   printf("case1\n");
  11.                 break;
  12.               } else {
  13.       case 2:   printf("case2\n");
  14.                 break;
  15.               }
  16.     }
  17.   }
  18. }
  19.  
  20. ultimation@NoizeBox:~/temp$ ./test
  21. We're in mode 0 and the if will fail
  22. case2
  23. We're in mode 1 and the if will fail
  24. case1
  25. We're in mode 2 and the if will fail
  26. case2
  27.  
  28. ultimation@NoizeBox:~/temp$ ./test
  29. We're in mode 0 and the if will not fail
  30. case1
  31. We're in mode 1 and the if will not fail
  32. case1
  33. We're in mode 2 and the if will not fail
  34. case2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement