while是打算机的一种基本循环模式。当知足条件时进入循环,进入循环后,当条件不知足时,跳出循环。while语句的一样平常表达式为:while(表达式){循环体}。
范例循环
WHILE

<条件> <语句体> end while do while <条件> <语句体>
loop
语法
javascript
JavaScript中while循环的目的是为了反复实行语句或代码块。
只要指定条件为true,循环就可以一贯实行代码块。
JavaScript中while循环的语法如下:
while (<条件>) {需实行的代码 };
do {需实行的代码 } while (<条件>);
把稳:do...while 循环是 while 循环的变种。该循环程序在初次运行时会首先实行一遍个中的代码,然后当指定的条件为 true 时,它会连续这个循环。以是可以这么说,do...while 循环为实行至少一遍个中的代码,纵然条件为 false,由于个中的代码实行后才会进行条件验证。
PHP
while 循环是 php 中最大略的循环类型。它和 C 措辞中的 while 表现得一样。语法如下:
while(expr){statement}
利用示例
Javascript
下面的例子定义了一个循环程序,这个循环程序的参数 i 的起始值为 0。该程序会反复运行,直到 i 大于 10 为止。i 的步进值为 1。
<html><body>
<script type="text/javascript">
var i=0
while(i<=10){
document.write("The number is"+i);
document.write("<br/>");
i=i+1;}
</script>
</body></html>
结果
The number is0
The number is1
……
The number is9
The number is10
PHP
<?php$num=1;$aaa="10以内的偶数为:";while($num<=10){if($num<=10){$aaa.=$sum."";}$sum++;}echo $aaa;?>
下面两个例子完备一样,都显示数字 1 到 10:
<?php$i=1;while($i<=10){echo $i++;}$i=1;while($i<=10):print $i;$i++;endwhile;
1. when和while在勾引状语从句时, 都可表示“当……的时候”。如
Doctor Smith called when / while we were preparing dinner.
当我们正在做饭的时候,史密斯年夜夫来访了。
While I was in Shanghai, I met with the pop star.
当我在上海时, 恰巧碰着了那位盛行歌星。
【把稳】
(1) when表示“当……的时候”,从句中既可以用延续性动词, 表示状态或韶光段, 也可以用非延续性动词, 表示动作或韶光点; while表示“当…… 的时候”、“在……期间”, 从句中只能用延续性动词, 表示状态或韶光段。
例如:
It was snowing when we arrived at the station.
When he came in, we all stood up, smiling.
I was very fat when / while I was a child.
When / While she was typing, someone knocked at the door.
(2)在when或while所勾引的状语从句中, 如果从句的主语和主句的主语相同, 且动词又是be动词时, 从句的主语和be动词每每可以省略。
例如:
When / While (I was) walking along the street, I heard my name called.
When / While (you’re) in trouble, turn to me for help.
2. when和while都可以表示“只管、虽然”, 但when常常指描述的事实或结果事与愿违或出人意料, 而while在语气上含有让步之意。例如:
The boy was watching TV when he should have gone to bed.
虽然那孩子该睡觉了, 但他还在看电视。
The old couple prefer walking when they might take a taxi.
只管可以坐出租车, 那对老夫妇更乐意步辇儿。
While I accept that he is not perfect, I do actually like the person.
只管我承认他并不完美, 但我确实真地喜好他这个人。
While he loves his students, he is very strict with them.
虽然他爱他的学生, 但对他们的哀求也很严格。
while的其它含义和用法:
(1) 然而, 可是
I like coffee, while my sister likes tea.
我喜好咖啡, 而我姐姐喜好喝茶。
I was preparing for the exam while they were chatting.
我在准备考试, 可他们却在闲聊。
(2) 只要
While there is water, there is hope of life.
只要有水, 就有生存的希望。
I’ll offer help to those poor children while I’m alive.
只要我活着, 就要帮助那些穷苦的孩子。
时态标志词
when和while勾引的句子可以作过去进行时的韶光状语,差异在于:when勾引的韶光状语从句可以接一段韶光或者一个详细的韶光点 while勾引的韶光状语从句只能接一个韶光点。如:
常日用在事情同时发生的情形,主句和从句都用过去进行时
Mother was cooking the meal while i was doing my homework.
当妈妈在做饭的时候,我正在做作业。
表示同时
表示而...的意味时,主句和从句的时态是同等的,即可以都是一样平常现在时,又可以都是一样平常过去时,如:
I like playing football while Jim likes playing basketball.
我喜好踢足球,然而吉姆喜好打篮球。
Yesterday my parents went to the cinema while I stayed at home.
昨天爸爸,妈妈去看电影了,而我呆在家里在。
总结
本日就分享到这里韶光也不早了该去跑步去了!
在接下来的文章中再来分享实战中的浸染
哈哈创造这个专业属于有点正经来个美图。
文章网络与网络,辛劳网络转载请备注出处全能大脸猫!
PHP|PHP之代码编写规范
PHP丨PHP根本知识之流程掌握for循环「理论篇」