B
broli
Hello, I tried to execute this example on switch and I got the output:
i <= 1
public class MySwitch
{
public static void main (String [] args)
{
int i = 0;
switch (i)
{
case 0:
case 1:
System.out.println ("i <= 1");
break;
default:
System.out.println ("i > 1");
}
}
}
Can some one explain to me why I get this output ? I remember from my
C lessons that if you don't put a break in any of the cases (like in
case 0), the program enters into an infinite loop.
i <= 1
public class MySwitch
{
public static void main (String [] args)
{
int i = 0;
switch (i)
{
case 0:
case 1:
System.out.println ("i <= 1");
break;
default:
System.out.println ("i > 1");
}
}
}
Can some one explain to me why I get this output ? I remember from my
C lessons that if you don't put a break in any of the cases (like in
case 0), the program enters into an infinite loop.