# Short-Circuit Logical Operators

sonali sawant

Greenhorn

Posts: 13

wise owen

Ranch Hand

Posts: 2023

posted 9 years ago

for (int z = 0; z < 5; z++)

{

if (( y-- > 7 ) || (++x > 2))

{

y--;

}

}

z=0:

(y-- > 7) is true and do y--; //x =0 y =8

z=1:

(y-- > 7) is true and do y--; //x =0 y =6

z=2:

(y-- > 7) is false and continue to evalute (++x > 2) which is false //x=1 y=5

z=3:

(y-- > 7) is false and continue to evalute (++x > 2) which is false //x=2 y=4

z=4:

(y-- > 7) is false and (++x > 2) is true then doing y--; //x=3 y=2

{

if (( y-- > 7 ) || (++x > 2))

{

y--;

}

}

z=0:

(y-- > 7) is true and do y--; //x =0 y =8

z=1:

(y-- > 7) is true and do y--; //x =0 y =6

z=2:

(y-- > 7) is false and continue to evalute (++x > 2) which is false //x=1 y=5

z=3:

(y-- > 7) is false and continue to evalute (++x > 2) which is false //x=2 y=4

z=4:

(y-- > 7) is false and (++x > 2) is true then doing y--; //x=3 y=2