Home  >  Article  >  Backend Development  >  What is the usage of while loop?

What is the usage of while loop?

hzc
hzcOriginal
2020-06-22 14:23:5412920browse

What is the usage of while loop?

#What is the usage of while loop?

while is a basic loop mode of computers. When the condition is met, it enters the loop. After entering the loop, when the condition is not met, it exits the loop. The general expression of the while statement is: while (expression) {loop body}.

The syntax format is:

Java

while(<条件>) {<语句;>}
do {<语句;>} while(<条件>);
二者的区别是do-while最少会被执行一次。
循环中可以使用continue结束当前循环,回到循环开始处开始下一次循环。也可以用break跳出整个循环。

PHP

while 循环是 php 中最简单的循环类型。它和 C 语言中的 while 表现得一样。语法如下:
while(expr){
statement
}

javascript

JavaScript中while循环的语法如下:
while (<条件>) {需执行的代码 };
do {需执行的代码 } while (<条件>);

c

do <语句> while(<条件>);
while(<条件>) <语句>;

C

while(<条件>) <语句>;
do <语句> while(<条件>);

Recommended tutorial: "php tutorial

The above is the detailed content of What is the usage of while loop?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn