Reputation: 1
I have encountered in some algorithm shortened syntax for the first time:
j -= i < 3;
Can you please explain to me what it means
Upvotes: 0
Views: 113
Reputation: 11
J-=1<3 is a boolean expression . which means j=j - 1<3 . here the compiler will examine the comparison between 1 and 3 which is true . true means in c++ 1 so j=j - 1 . this expression is the same as j- -
Upvotes: -1
Reputation: 409166
The expression i < 3
is a boolean expression. It's either true
or false
In C++ true
and false
are implicitly convertible to the int
values 1
and 0
(respectively).
So depending on the value of i
it's either equal to
j -= 1; // i < 3 is true
or
j -= 0; // i < 3 is false
Upvotes: 4