# Thread: Why is it that my program does not print for case 1?

1. ## Why is it that my program does not print for case 1?

Code:
```main()
{

int x=0;
switch(x)
{
case 1: printf( "One" );
case 0: printf( "Zero" );
case 2: printf( "Hello World" );
}
}```

2. Because it does. In fact, it will print "OneZeroHello World".

3. >> Why is it that my program does not print for case 1?

Because it doesn't equal 1, maybe?

>> In fact, it will print "OneZeroHello World".

It'll actually skip the first case label, so the output would be "ZeroHello World".

4. Why would you expect it to? Fall-through doesn't mean it always hits every case label. It means if it matches one, and there's no fall-through protection (break), it will do everything that comes after it until it finds a reason to stop.

Quzah.

5. When it falls through, it falls down, not up.
Set x=1 and it'll print them all.

6. Originally Posted by Sebastiani
Because it doesn't equal 1, maybe?
Ha! That will (okay, should) teach me to read the code and not the question.

7. Originally Posted by tabstop
Ha! That will (okay, should) teach me to read the code and not the question.
lol. Do you know about the break statement Jasper?

8. I think the problem was to illustrate the out of order sequence of the case statements and how it will effect the outcome. I think he was suppose to test the code and learn. Personly instead of changing x to equal 1 I would simply change the case 1: to case 0: and case 0: to case 1: keeping the outputs in the same order. If the point was to get all three to print. :P

Like :
Code:
```main()
{

int x=0;
switch(x)
{
case 0: printf( "One" );
case 1: printf( "Zero" );
case 2: printf( "Hello World" );
}
}```

9. Originally Posted by strickyc
I think the problem was to illustrate the out of order sequence of the case statements and how it will effect the outcome. I think he was suppose to test the code and learn. Personly instead of changing x to equal 1 I would simply change the case 1: to case 0: and case 0: to case 1: keeping the outputs in the same order. If the point was to get all three to print. :P

Like :
Code:
```main()
{

int x=0;
switch(x)
{
case 0: printf( "One" );
case 1: printf( "Zero" );
case 2: printf( "Hello World" );
}
}```
You'd rather change 2 things than 1?

10. case 0: printf( "One" );
case 1: printf( "Zero" );
I hope all of your code doesn't end up as "clear" as this.

Quzah.

11. Jus a nitpick, but you have things backwards - case 0 is printing 'one' and case 1 is printing 'zero' in the "fixed" code.