Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of the do while statement in php

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the relevant knowledge of "what is the use of do while sentences in php". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer

What is the use of the php do while statement?

Do...while-executes the code block once, and then repeats the loop when the specified condition holds

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.

Grammar

Do {Code to be executed;} while (condition)

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 2The number is 3The number is 4The number is 5The number is 6

The do-while loop is very similar to the while loop, except that the value of the expression is checked at the end of each loop rather than at the beginning. The main difference with the general while loop is that the do-while loop statement guarantees that it will be executed once (the truth of the expression is checked after the end of each loop), but not necessarily in the general while loop (the truth of the expression is checked at the beginning of the loop, if it starts with false, the whole loop ends immediately).

This is the end of the content of "what is the use of do while sentences in php". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report