Sorry if this is too simple. I want to know which of the conditionals is happening exactly. Is there a way more able to capture this without repeating them inside the block with if structures? I am using C language.
while ( l < 0 || l > 2 || c < 0 || c > 2 )
You could use comma expressions, i.e. something like (expr1,expr2)
, which are always evaluated left to right with a sequence point at each ,
; So you may rely on that expr1
is evaluated before expr2
, whereas the latter serves as the comma expression's result then.
With that, the following should work, and x
will bee in the range of 0..3
, depending on which condition got true:
int x;
while ( (x=0,l < 0) || (++x,l > 2) || (++x,c < 0) || (++x,c > 2) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With