![]() |
Looping Through Exponents
This works fine as 1, 2, 3, 4, 5, 6, 7, 8, 9:
PHP Code:
PHP Code:
|
Quote:
You can only use ++ or -- :thumbsup: |
Actually I think what you meant to do was:
Code:
for ($i = 1; $i < 10; $i<<=1) { |
Tracknut sums it up.
The post condition in the for loop must result in something that changes control. The increment and decrement operators are (at least I'm pretty sure) the only two in PHP that alter the state of the variable when applied. The other unary operators like boolean and bitwise nots (! and ~) only work on the returned result of the operation, and likewise the binary operations (ie $i << 1 or $i + 1) would require assignment back to the $i in order to alter it. |
| All times are GMT +1. The time now is 02:16 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.