#Boolean operators in For Loops

1 messages · Page 1 of 1 (latest)

sinful condor
#

int i = 5, j = 2, k = 4, l = 3, m = 7, n = 8;
for ( i = 1, j = 3, k = 4; i++ < l || ++j < m && k < n; )
cout << i << " " << j << " " << k << " " << l << " " << m << endl;

OUTPUT:

2 3 4 6 7 Should j be 4 here instead as you are incrementing it by one ?
3 3 4 3 7
4 4 4 3 7
5 5 4 3 7
6 6 4 3 7

buoyant mortarBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

restive flicker
#

in the comparison the
i++ < l is true, so there is not a need to check for the right of the or

#

aka

#

no need to check
++j < m

#

if left hand side is true

sinful condor
#

but i is = 1

restive flicker
#

sorry for format, im on mobile

restive flicker
sinful condor
#

so you check the right side of the condition right

#

cause one side of the or is false

restive flicker
restive flicker
restive flicker
sinful condor
#

if the left side was false how would it work

restive flicker
#

then it would check the right side of the ||

sinful condor
#

would you check the next condition or would you do the and operator and then compare it

#

since and has precedence over or

restive flicker
#

it would check ++j < m

sinful condor
#

so when does the precedence come into play

#

or and being more priority than or

restive flicker
#

im not aware that and has priority over or

#

i am also a newish c++ enjoyer so maybe it is true but i dont think so

sinful condor
#

i++ < l || (++j < m && k < n) is this technically how it is

#

you can put brackets around the and stuff

restive flicker
#

if that were the case, j would be 4 in the output. no?

#

its just left to right without priority

#

unless there are parenthesis

sinful condor
#

ok thanks

buoyant mortarBOT
#

@sinful condor Has your question been resolved? If so, run !solved :)

sinful condor
#

!solved