Here's the code:
#include <stdio.h>
int main ()
{
int menu=0;
while (menu!=3)
{
scanf ("%d", &menu);
switch (menu)
{
case 1:
{
printf ("Case 1\n");
continue;
}
case 2:
{
printf ("Case 2\n");
break;
}
}
printf ("This doesn't get printed by case 1\n");
}
return 0;
}
Every time I put it 1, that printf won't show up, but other than that, it works well. So how continue
and break
works for switch
inside a loop
? Why break
doesn't break the loop? Instead, it prevents the next cases to be done right? But what about continue
? To be clear, I'm actually asking how is it different and how those actually work. Note: I've done this too in java (with eclipse).