Differences between a while loop and a for loop in PHP?

前端 未结 6 2069
梦谈多话
梦谈多话 2020-12-06 12:02

I\'m reading an ebook on PHP right now, and the author noted that the difference between a while loop and a for loop is that the for loop will count how many times it runs.<

6条回答
  •  萌比男神i
    2020-12-06 12:18

    Can you? Yes, certainly. But whether or not you should is an entirely different question.

    The for loop is more readable in this scenario, and is definitely the convention you'll find used within virtually every language that has looping directives. If you use the while loop, people are going to wonder why you didn't use a for loop.

提交回复
热议问题