Alex Rivera | Logout

if without condition?

Asked 2010-11-26T15:28:25.547
11

I just found this "C++" today and i cannot make sense of it:

if(array[i][j]) {--i;--j;}

can anyone explains to me how this work? I just don't get it. What is the condition here? It seems like it would be true every time, but when i got rid of the IF (so only this {--i;--j;} left.) it doesn't work the same.

I'm quite new to C++ so go easy with the explanations! :)

Thanks!

Edit
Report

1 Answer

3

The if is gets a true if array[i][j] gets true when cast to a bool. If array has e.g. float or intvalues, anything not equal to 0 will be cast to true. The situation could be different for user-defined types.

answered 2010-11-26T15:31:36.333

Your Answer