What is it exactly you're trying to do in this code? Why do you sometimes need to do it 50 times and sometimes only once? What I would do is put that code into its own function, which you can then call inside of a for loop or a while loop to control how many times it gets executed. Alternatively, you could use just use a while or do while loop like this:
Code:
$iternum=whatever;
while(i<iternum) { <above code here> i++; }
But really, if you're going to be doing this operation multiple times in different parts of your program, best be putting it in its own function.
also: quick primer on loops:
for(<declaration>;<test>;<increment>) {}
the for loop executes as long as the <test> condition is met, based on <declaration> and <increment>, for ex
for(int i=0;i<4;i++){}
will loop 4 times (as long as i<4, incrementing i by one each time through the loop)
while(<test>){}
this loops as long as the test condition is true, without any built-in counter. ex
while(true) loops forever
while(input!=0) loops until the user enters zero
do{}while(<test>) same as a while loop, except whats in the brackets is guaranteed to be executed at least once. in the previous example, input may have been undefined, or a nonsense value, the first run through, so it would have been better to use a do while loop, ex:
do{ input=getinput(); } while (input!=0);