# Simple Explanation Needed

• 07-09-2007
slowcoder
Simple Explanation Needed
When something like this is done in C:

Code:

```int i; const static char phase[] = "urrrddd"; for (i = 0; phase[i]; i++) {     /* some code */ }```
is phase[i] a shorter way of saying: phase[i] != 0
or something else? Thanks
• 07-09-2007
hk_mp5kpdw
Pretty much.
• 07-09-2007
Govalant
When you don't specifiy a condition it evaluates to true if it is different than zero so phase[i] and phase[i]!=0 are the same thing when already compiled.

And that loop will run while the string isn't terminated.
• 07-10-2007
MacGyver
Boolean expressions in C are numerical expressions as well, and they are resolved in the following way: Every number and expression that results to a non-zero value is true, while every expression that results to zero is false.
• 07-10-2007
slowcoder
Perfect, thank you for all the explanations.

One more simple question that is similar.

Code:

```int multi_tile, norec, opt_DM; /*some code*/ multi_tile = norec && opt_DM < 32;```
For the code above, is there a long way of coding that last line...maybe with an if statement? I'm trying to get a better idea of how '&&' and '<' are being used to give the value of multi_tile. Thanks for the help
• 07-10-2007
Govalant
Quote:

Originally Posted by slowcoder
Perfect, thank you for all the explanations.

One more simple question that is similar.

Code:

```int multi_tile, norec, opt_DM; /*some code*/ multi_tile = norec && opt_DM < 32;```
For the code above, is there a long way of coding that last line...maybe with an if statement? I'm trying to get a better idea of how '&&' and '<' are being used to give the value of multi_tile. Thanks for the help

multi_tile will be 1 only if norec is different than zero and opt_DM is less than 32.

if those conditions are not true multi_tile will be zero.

Boolean expresions evaluate to 1 or 0, indicating true and false.
• 07-10-2007
slowcoder
So just to verify that I interpreted that properly, this would be the equivalant?

Code:

```int multi_tile, norec, opt_DM; /*some code*/ if ((norec != 0) && (opt_DM < 32))   multi_tile = 1; else   multi_tile = 0;```
Thank you Govalant!
• 07-10-2007
Govalant
Exactly =)