how can i get this done

Discussion in 'PHP' started by mumfry, Jul 12, 2010.

  1. #1
    hey yall

    i would like to take a number and keep adding 20 to it till it get to a certain point then stop
    for instance, lets say the number is 10. Then i would like to keep adding 20 to it till it gets to say... 100
    so it would be something like this
    10
    30
    50
    70: and so on till 100.

    i tried it in a for loop but i could only get it to increment by 1 instead of 20

    would be grateful for any solution to this
    thanks

    how can i get this result
     
    mumfry, Jul 12, 2010 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    try this

    <?php
    $i=10;
    while($i<=100)
    {
    echo "The number is " . $i . "<br />";
    $i = $i + 20;
    }
    ?>
     
    Bohra, Jul 12, 2010 IP
  3. mumfry

    mumfry Active Member

    Messages:
    118
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    woow
    nice bohra
    very nice
    thanks for the help
    much appreciated
     
    mumfry, Jul 12, 2010 IP
  4. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #4
    If its incrementing only by 1, you aren't referncing the loop correctly; e.g

    <?php
    for ($x=10; $x<100; $x+=20)
      {
      print "number = $x\n";
      }
    ?>
    PHP:
    OUTPUT:

    number = 10
    number = 30
    number = 50
    number = 70
    number = 90
     
    lukeg32, Jul 12, 2010 IP
  5. mumfry

    mumfry Active Member

    Messages:
    118
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #5
    tanks luke
    yea i didn't create the loop like that.
    for the last part i had it as $x++ instead of $x+=20.
    thanks for the correction
     
    mumfry, Jul 12, 2010 IP
  6. sanhit

    sanhit Peon

    Messages:
    318
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    seems ur problem solved :) if need some more help like this you can PM me anytime.
     
    sanhit, Jul 16, 2010 IP