In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the usage of While loop in PHP". In daily operation, I believe that many people have doubts about the usage of While loop in PHP. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the usage of While loop in PHP". Next, please follow the editor to study!
PHP cycle-While cycle
Loop the number of times the code block is specified, or loop through the code block when the specified condition is true.
.
PHP cycle
When you write code, you often need to have the same block of code run over and over again. We can use loop statements in our code to accomplish this task.
In PHP, the following loop statements are provided:
Http://www.iis7.com/b/wzjk/
While-Loops the block of code as long as the specified condition is true
Do...while-executes the code block once, and then repeats the loop when the specified condition holds
For-the number of times that the code block is executed in a loop
Foreach-loops the code block based on each element in the array
.
While cycle
The while loop executes the code block repeatedly until the specified condition is not established.
Syntax:
While (conditional)
{
Code to be executed
}
Example:
The following example first sets the value of the variable I to 1 ($item1;).
Then, the while loop will continue to run as long as I is less than or equal to 5. Each time the loop runs, I increments by 1:
Output:
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
.
Do...while statement
The do...while statement executes the code at least once, then checks the condition, and repeats the loop as long as the condition is established.
Syntax:
Do
{
Code to be executed
}
While (conditional)
Example:
The following example first sets the value of the variable I to 1 ($item1;).
Then, start the do...while loop. The loop increments the value of the variable I by 1 and then outputs it. First check the condition (I is less than or equal to 5), as long as I is less than or equal to 5, the loop will continue to run:
Output:
The number is 2
The number is 3
The number is 4
The number is 5
The number is 6
At this point, the study of "the use of the While loop in PHP" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.