Which loop is faster, while or for?

后端 未结 16 2347
我寻月下人不归
我寻月下人不归 2020-11-27 07:07

You can get the same output with for and while loops:

While:

$i = 0;
while ($i <= 10){
  print $i.\"\\n\";
  $i++;
};
         


        
16条回答
  •  一个人的身影
    2020-11-27 07:33

    It shouldn't matter which is faster. If it does matter then benchmark it using your real code and see for yourself.

    The answers to this other question might be useful as well: How to write more efficient code

提交回复
热议问题