11

Currently I have a code that looks like:

for ($i=0; $i<=($num_newlines - 1); $i++) 
{
$tweetcpitems->post('statuses/update', 
                    array('status' => wordFilter("The item $parts[$i]  has been released on Club Penguin. View it here:   http://clubpenguincheatsnow.com/tools/swfviewer/items.swf?id=$parts[$id]")));
sleep(90);
}

What I want to do make the "i++" part add by two and not one, but how do I do this? Please help!

2
  • You may want to spend a little time getting a basic understanding about how flow statements like for work (and PHP code in general). This is a pretty trivial question. Commented May 24, 2012 at 20:57
  • 1
    Yes, I understand that this question was pretty basic, but I wanted to make sure that I got it correct because I didn't want to end up with an infinite loop. Something like it happened to me before, and I don't want to risk another chance. I always have to ask the pros at SOF. :) Commented May 24, 2012 at 21:11

3 Answers 3

37
for ($i=0; $i<=($num_newlines - 1); $i+=2) {
Sign up to request clarification or add additional context in comments.

1 Comment

curious, why wouldnt you do for ($i=0; $i<$num_newlines ; $i+=2)
6
$i++ : increment by one

$i+=2 : increment by two

$i+=3 : increment by three

etc..

Comments

0

For those who are looking to increment pair of numbers (like 1-2 to 3-4):

Solution one:

//initial values
$n_left = 1;
$n_right = 2;

for ($i = 1; $i <= 5; $i++) {
    
    print "\n" . $n_left . "-" . $n_right;   
    
    $n_left =+ $n_left+2;
    $n_right =+ $n_right+2; 
}
//result: 1-2 3-4 5-6 7-8 9-10

Solution two:

for ($y = 0; $y <= 9; $y+=2) {
    
    print "\n" . ($y+1) . "-" . ($y+2);  

}
//result: 1-2 3-4 5-6 7-8 9-10

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.