You are invited to Log in or Register a free Frihost Account!

# Help with a php for() function

Gundamxxg
im trying to figure out if there is a way to increment by more than one in a for loop.

standard iteration is
 Code: for(\$i = 0; \$i < x; \$i++) { code goes here }

what i am trying to do is increment through the numbers by a value of 10.
mathiaus
 Code: for(\$i = 0; \$i < \$x; \$i+10) {   code goes here }

The last bit in the for. ++ adds 1, just change and add a number :)

** Also x is not a number. \$x might well be a variable but x isn't
Gundamxxg
yeah i was just using x in place of a standard variable rather than just a php variable.

I think i figured out what i was trying to do tho,

this is pretty much what i did, and its kinda what i was looking for.

 Code: for(\$i = 0; \$i < \$x; \$i++){ \$i = \$i+3; echo \$i; }

returns to me 3, 7, 11, 15 yada yada yada.

basically what i am trying to do is write something that will output the rgb values of a region of pixels of an image.
kv
 Code: for(\$i=0; \$i<\$x; \$i=\$i+10 ) {     echo \$i; }
Fire Boar
Gundamxxg wrote:
yeah i was just using x in place of a standard variable rather than just a php variable.

I think i figured out what i was trying to do tho,

this is pretty much what i did, and its kinda what i was looking for.

 Code: for(\$i = 0; \$i < \$x; \$i++){ \$i = \$i+3; echo \$i; }

returns to me 3, 7, 11, 15 yada yada yada.

basically what i am trying to do is write something that will output the rgb values of a region of pixels of an image.

 Code: for (\$i = 3; \$i < \$x; \$i + 4) {     echo \$i; }

That's the neatest way of doing it. Oh, and by the way, what you were saying about x isn't quite true if you had something like this:

 Code: define('x', 4); for (\$i = 0; \$i < x; \$i++) {   code here }

That would be a valid For loop from 0 to 4.
Related topics

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP