If Statements

closed account (zb0S216C)
This has been really bugging me. I see codies using if statements like this:
1
2
3
int Variable( 10 );
if( Variable )
    // do something... 

I don't understand it. What is it testing for? Can anybody explain this?
It's testing whether Variable's value is non-zero.
Last edited on
closed account (zb0S216C)
Simple enough. Thanks, Filipe.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int n = ...;
bool b = n; //implicit cast

//now
if( n == 0 )
	assert( b == false );
else
	assert( b == true );

//or
if( b )
	assert( n != 0 );
else
	assert( n == 0 );
Topic archived. No new replies allowed.