词条 | while |
释义 | 计算机语言中的循环语句计算机的一种基本循环模式。当满足条件时进入循环,不满足跳出。 BASIC语言中的当型循环WHILE <条件> <语句体> end while do while <条件> <语句体> loop Pascal语言中的当型循环while <条件> do <语句> C语言中的当型循环do <语句> while(<条件>); while(<条件>) <语句>; C++语言中的当型循环while(<条件>) <语句>; do <语句> while(<条件>); Java语言中当型循环while(<条件>) {<语句;>} do {<语句;>} while(<条件>); 二者的区别是do-while最少会被执行一次。 循环中可以使用continue结束当前循环,回到循环开始处开始下一次循环。也可以用break跳出整个循环。 PHP语言中的当型循环while循环是php中最简单的循环语句。语法如下: while(expr){ statement } 发开语言使用示例:Php中的while<?php $num = 1; $aaa = "10以内的偶数为:"; while($num <= 10){ if($num <= 10){ $aaa .= $sum.""; } $sum++; } echo $aaa; ?> C#中的while语句while (TRUE) { <code to be looped> } eg: int i = 1; while (i <= 10) { Console.WriteLine("{0}", i++); } Java中的While1、while(true) {i++; }/i无限累加,死循环/ 2、do{i++;} while(i<60)/在i小于60的情况下进行累加/ Basic中的WhileDim i As Integer i = 1 Do While i <= 5 Print i i = i + 1 Loop'向屏幕输出从1到5的正整数 AS语言中的当型循环:do{语句}while(条件语句); 循环输出测试示例: var i = 1; while( i<= 1000) { i ++; } trace(i) Pascal语言中的Whilek:=10; WHILE k>0 DO BEGIN Writeln (k); k:=k-1 END; 从10到1倒序输入 英语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. 只要我活着, 就要帮助那些贫困的孩子。 |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。