# Why \$i > 4 and not &i < 4 ?

So the second variable is stating when the loop should stop, so, if i'm counting from 50 to 5 why should i say that \$i > 4 (So is major than 4) and not \$i <4 (to stop when is minor than 4, which seem more logical), i'm sure i'm missing something but i can't get what.

Thanks in advance for any help.

I think you're confusing the 2nd element as an instruction for when to STOP counting. It's actually an instruction to CONTINUE AS LONG AS... (in this case \$i > 4)

So... if the variable is Greater than 4 ( \$i > 4 )... keep counting down.

Kelly O'Hara about 5 years ago

Absolutely right... Think of it as for every time you're ready to start the next loop, you are checking whether you should go through or finally skip out. It looks at the second part and basically solves the expression....

In this case:

First pass, \$i is equal to 50 and we look at the second element and determine if we should still run.

• In the valid case, \$i > 4 evaluates to "True", so yes, the loop should continue.
• In your opposing case \$i < 4, the very first pass (with \$i = 50) it will evaluate to "False" and say "we're done, skip the loop". In that case, it won't even run in the loop, it'll just skip over it.

An alternative that should work as well (only in specific iterative cases where the value matches a valid value in the iterator) would be to check for the value, like \$i != 5. Then that would work in either direction, just as long as \$i isn't 5. But then you would lose that iteration, so you would look for the next valid value in the group, \$i != 0. Now that would work, as the last valid value is 5. It's not the brightest (iterator step changes, your conditions have to be modified to match) or most effective manner to write it, but it does work and might help to understand the for looping better.