+ 1
How to put more than two conditions in for loop?
I typically have doubts how we use continuous expression in for loop e. g. (for int x=0; x>50, x<100; x+=2) or how can we use nested for loops in one statements
2 Answers
+ 1
If you want the loop to proceed while <x> > 50 and <x> < 100 you can chain the expressions in condition by logical AND operator &&.
for(int x = 0; x > 50 && x < 100; x += 2)
What operator is used between the expressions is up to the necessity (not always logical AND).
(Edit)
FYI, considering <x> init by zero, the condition <x> > 50 will not satisfy, and loop won't start.
0
Add &&
for(int x=0;x>50&&x<100;x+=2)