java中while的用法

2024-10-27 15:54:09
推荐回答(3个)
回答1:

从一道高考题综述while的用法

先看下面一道高考题:

-I\”m going to the post office.

-________you\”re there, can you get me some stamps?

A. As B. While C. Because D. If

对连词的用法考查在每年高考题中均有涉及。Because引导原因状语从句, If引导条件状语从句,按题干提供的情景均不可取。While和As都能引导时间状语从句,极易混淆。As一般强调主句谓语动词与从句谓语动词动作的同时性,而While除可表示同时性外,还含有一个动作在另一个动作正在进行或持续过程中的某一时刻发生。再从题干所提供的情景判断,就可知道B为最佳答案。

while的用法可从下述几点理解与运用。

一、while意为\"当......时候\",指一段时间,不能用来表示一个时间点。

While the discussion was still going on, George came in. 当讨论还在进行时,乔治走了进来。

二、while意为\"而;然而\",表示转折。

There\”re plenty of rain in the southeast, while there\”s little in the northeast. 东南部雨量充足,而西北部则很少下雨。

三、while意为\"虽然;尽管\",表示让步。

While I admit his good points, I can see his shortcomings. 尽管我承认他的优点,但我还是能看到他的缺点。

四、while意为\"只要\",表示条件。

We can surely overcome these difficulties while we are closely united. 只要我们紧密地团结一致,一定能克服这些困难。

五、while从句中的省略。

当while从句中的主语与主句的主语一致,且含有be的某种形式时,从句中的主语连同be可同时省略。

While listening to the radio, she fell asleep. 她在听收音机时睡着了。

While in London, he studied music and painting. 在伦敦时,他学习音乐和绘画。

六、while可用作名词,意为\"一会儿;一段时间\"。

作名词用时,主要用于短语中: after a while \"过了一会儿\"; all the while \"一直,始终\"; a short / little while ago \"刚才\"; once in a while \"偶尔,间或\"; wait / rest(for) a while \"等 / 休息一会儿\"。

I haven\”t seen her for a long while.我好久没有看见她了。

Where have you been all this while?这一阵子你到哪去了?

He usually goes to work by bike, but once in a while he goes by bus. 他通常骑自行车上班,但偶尔也乘公共汽车。

I looked everywhere for the letter, but it was in my pocket all the while. 我到处找那封信,却不知它一直在我口袋里。

七、while与when以及as之间的区别。

1. 当从句中的谓语动词是持续性的动作时,我们可以用while, when或as。

While / When / As I was walking down the street, I noticed a police car in front of the bank.我顺着马路往前走时,发现银行门前停着一辆警车。

2. 当从句中的谓语动词表示瞬间动作时,不可用while。

He was on the point of leaving when someone knocked at the door. 他正要走,这时有人敲门。

3. 如果谈论两个长动作,最常用的是while。

While John was sitting biting his nails, I was working out a plan to get us home. 约翰坐在那里咬指甲时,我想出了一个回家的办法。

不过, as是可以用来说明两种正在发展或变化的情况的,这时as引导一个持续性的动作,主句中的动作与之同时进行。

As we talked on, he got more and more excited. 我们继续往下谈的时候,他越来越兴奋。

4. 如果表示两个短动作或事件同时发生,最常用的是as或just as,也可用when。

Just as he caught the ball, there was a tearing sound. 当他抓住球的时候,有一种撕裂的声音。

I thought of it just when you opened your mouth. 就在你要说话的时候,我也想到了。

回答2:

while一般用于 不清楚需要循环多少次的情况下
while(true){ //循环条件中直接为TRUE
//循环内容
if(符合某条件){ //直到符合条件后跳出本循环 否则一直循环下去
break;
}
}

回答3:

while(boolean){
//循环内容
}