Re: [PHP] incrementing in a for loop

2005-09-13 Thread Burhan Khalid

Peppy wrote:

I've searched online and am unable to find how to increment by more than one in 
a for loop.

for ($i = 1; $i = 6; $i++) {

Is it possible to increment $i by 5?


Everyone has responded with the correct answer, but you do realize that 
this loop will only run twice? It will print 1, then 6.


If you change it to $i  6, then it will print 1.

And just because its Tuesday, and if you happen to be using PHP 5.0.0+:

$numbers = range(1,100,5);
foreach($numbers as $number)
{
   echo $number.\n;
}

And now, back to your regularly scheduled programming

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] incrementing in a for loop

2005-09-12 Thread Peppy
I've searched online and am unable to find how to increment by more than one in 
a for loop.

for ($i = 1; $i = 6; $i++) {

Is it possible to increment $i by 5?

Thanks.


Re: [PHP] incrementing in a for loop

2005-09-12 Thread Philip Hallstrom
I've searched online and am unable to find how to increment by more than 
one in a for loop.


for ($i = 1; $i = 6; $i++) {

Is it possible to increment $i by 5?


Sure.

for ($i = 1; $i = 6; $i+=5) {

-philip

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] incrementing in a for loop

2005-09-12 Thread Stephen Johnson


On 9/12/05 12:39 PM, Peppy [EMAIL PROTECTED] wrote:

 for ($i = 1; $i = 6; $i++) {
Is it possible to increment $i by 5?

for ($i = 1; $i = 6; $i+5) {


-- 
Stephen Johnson
The Lone Coder

http://www.ouradoptionblog.com
*Join us on our adoption journey*

[EMAIL PROTECTED]
http://www.thelonecoder.com

*Continuing the struggle against bad code*
--

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] incrementing in a for loop

2005-09-12 Thread D A GERM

this worked for me:

[CODE]
   for ($myLoop = 0; $myLoop  100; $myLoop= $myLoop + 5)
   {
   print Pmy loop: $myLoop;
   }
[/CODE]

Peppy wrote:


I've searched online and am unable to find how to increment by more than one in 
a for loop.

for ($i = 1; $i = 6; $i++) {

Is it possible to increment $i by 5?

Thanks.

 



--
D. Aaron Germ
Scarborough Library, Shepherd University
(304) 876-5423

Well then what am I supposed to do with all my creative ideas- take a bath and wash 
myself with them? 'Cause that is what soap is for (Peter, Family Guy)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] incrementing in a for loop

2005-09-12 Thread M. Sokolewicz

Stephen Johnson wrote:


On 9/12/05 12:39 PM, Peppy [EMAIL PROTECTED] wrote:



for ($i = 1; $i = 6; $i++) {
Is it possible to increment $i by 5?



for ($i = 1; $i = 6; $i+5) {



that won't work; have you tried it?
Because $i++ assigns the result of $i+1 to $i, while yours does not 
assign anything to $i. This means you'll run an eternal loop ;)

to do what you showed, you'll need to change $i+5 to $i=$i+5 or $i += 5

- tul

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] incrementing in a for loop

2005-09-12 Thread Stephen Johnson
You are correct -- forgive the typo (I forgot the = ).

That is what I get trying to reply to email while eating a burrito and
talking on the phone. LOL
 
?php
/*

Stephen Johnson c | eh
The Lone Coder

http://www.ouradoptionblog.com
Join our journey of adoption

http://www.thelonecoder.com
[EMAIL PROTECTED]

continuing the struggle against bad code

*/ 
?


 From: M. Sokolewicz [EMAIL PROTECTED]
 Date: Mon, 12 Sep 2005 23:48:05 +0200
 To: Stephen Johnson [EMAIL PROTECTED]
 Cc: Peppy [EMAIL PROTECTED], php-general@lists.php.net
 Subject: Re: [PHP] incrementing in a for loop
 
 
 
 
 that won't work; have you tried it?
 Because $i++ assigns the result of $i+1 to $i, while yours does not
 assign anything to $i. This means you'll run an eternal loop ;)
 to do what you showed, you'll need to change $i+5 to $i=$i+5 or $i += 5

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] incrementing in a for loop

2005-09-12 Thread Chris W. Parker
D A GERM mailto:[EMAIL PROTECTED]
on Monday, September 12, 2005 1:01 PM said:

 [CODE]
 for ($myLoop = 0; $myLoop  100; $myLoop= $myLoop + 5)
 {
 print Pmy loop: $myLoop;
 }
 [/CODE]

Where's the code?


Oh there it is!

:)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php