# while loop question

I need to run a a chunk of code for 50 times.

Then increment a variable by 50 in that code and run it again and each time add another 50 to the variable until I have run the code a total of 3500 times.
###### Who is Participating?

Fixer of ProblemsCommented:
The simplest way is to put a loop inside a loop.  Since 3500 / 50 = 70...
``````<?php
\$x = 0;
for (\$i = 1; \$i <= 70; \$i++) {
for (\$j = 1; \$j <= 50; \$j++) {
echo \$j;  // do something here
}
\$x = \$x+50;
}
?>
``````
0

Fixer of ProblemsCommented:
Typically that is done with a 'for' loop because a 'for' is done by the count.  A 'while' can too but the logic for the count is part of the 'for' loop.  http://php.net/manual/en/control-structures.for.php
0

Author Commented:
With my question using the information can you show me an example?
0

Author Commented:
;)
This looks so intimidating. I'm having trouble understanding it. I know I'm very basic.
0

Senior Director of TechnologyCommented:

The loop in defining a counter (I) that starts at the value 1. Every time the loop is executed the value of I will be incremented by 1. This is what the I++ is doing.  the middle section of the for loop line is defining how many times the loop will run. So the above will keep looping while I is less than or equal to 70. If you wanted the loop to run 3500 times you would change that number. Hope that helps.
0

Fixer of ProblemsCommented:
The inner loop runs 50 times each time.  The outer loop runs 70 time and each time it runs, it runs the inner loop.  70 x 50 = 3500.  \$x is there only because you wanted to add 50 to something each time the inner ran.
0

Author Commented:
That was it thank you all for being so informative!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.