Bool question?

How do equations in bools like this determine if it's true or false, and also after it does the first x*=1, how does it know whether to go onto the else or not?

Usually I've seen codes like... if(something is true)>> if not do this. This code, how do I tell if the x*=i is true or false?
1
2
if (i) x*=i;
else x+=1;
@hellworld136

If i is a 0, then i is false, but if it equals 1 or more, it's true. So, with line 1, if i is true, then x will equal x plus x times i, otherwise, x will equal x plus 1. It's easier to understand the logic, if each command is on a separate line.
1
2
3
4
if ( i )
  x*=i;
else
  x+=1;
Last edited on
Thanks, I get it now. So if there's an int value where a bool should be, anything other then a 0 is true.
@hellworld136

Correct. Even if the value is a negative number.
Last edited on
Topic archived. No new replies allowed.