如何根据东西改变while循环条件?

by this question what i mean is that if, by example, someone's username is "bob" then the while loop condition will be ($i < 10), and if the username is something else then the while loop condition will be ($i > 10)

if($username == "bob")
{
   //make this while loop condition: ($i < 10)
   // it means: while($i <10){ so stuff}
}
else
{
   //make the while loop condition: ($i >10)
}

Try making two different while loops within the if and else blocks.

Is this what you mean? You can just take a different path depending on the success or failure of the if. If the code inside is the same, just call a method to avoid duplicating it.

if($username == "bob")
{
   //make this while loop condition: ($i < 10)
   // it means: while($i <10){ so stuff}
   while ($i < 10) {
       call_method();
   }
}
else
{
   while ($i > 10) {
       call_method();
   }
}

Make do_stuff a function, then this is perfectly readable (although special-casing 'bob' seems doubtable at best).

if($username == "bob")
{
   while($i<10) {
       do_stuff();
   }
}
else
{
   while($i>10) {
       do_stuff();
   }
}

To keep your code simple:

if($username == "bob") { while ($i<10){ }

} else { while ($i>10){ }

}

There are other better ways to handle it but they may make your code difficult to understand like using eval which I dont like.

while( ($username == 'bob' && $i <10 ) XOR $i > 10){}

$username == 'bob' will be evaluated first if it comes out to be true then $i < 10 is evaluated.

$var1 XOR $var2 is true only when one of $var1, $var2 is true but not both.

But I myself will go with this.