Jump to content

Is there a way to have multiple instances of 'while'?


soma56

Recommended Posts

I know it's a stupid question however if I had a simple program that did this:

 

<?PHP

//INSTANCE ONE
$i = 1;
while ($i <= 10) {
    echo $i++; 
}

//INSTANCE TWO
$A = 1;
while ($i <= 10) {
    echo $A++; 
}

//INSTANCE THREE
$Z = 1;
while ($i <= 10) {
    echo $z++; 
}

?>

 

What seems to happen is that the program will output each one in order before moving to the next 'while' rather then all at the same time or 'simultaneously' output all three.

 

Just curious if there's another way.

I know it's a stupid question however if I had a simple program that did this:

 

<?PHP

//INSTANCE ONE
$i = 1;
while ($i <= 10) {
    echo $i++; 
}

//INSTANCE TWO
$A = 1;
while ($i <= 10) {
    echo $A++; 
}

//INSTANCE THREE
$Z = 1;
while ($i <= 10) {
    echo $z++; 
}

?>

 

What seems to happen is that the program will output each one in order before moving to the next 'while' rather then all at the same time or 'simultaneously' output all three.

 

Just curious if there's another way.

 

For the most part, computers can do nothing simultaneously. Each action comes before the other. What is your desired output?

If you want to output all three at the same time, collect them in a string or look into output buffering via ob_start and ob_get_clean.  And then just echo that one string and viola. If you are wanting it to run all 3 simultaneously, I know of no way to do it other then opening 3 different pages which have 3 different whiles "at the same time".

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.