为您找到与while是连词相关的共27个结果:
我们在英语中,经常会运用到While,但很多学生不了解它的用法,导致使用时频频出错,让我们一起看看While的用法有哪些?下面是小编给大家带来的While的用法小结_While的短语搭配,以供大家参考,我们一起来看看吧!
▼While的用法小结
▼While的短语搭配
▼While的近义词
While的用法相关
浏览量:2
下载量:0
时间:
1.从句动作在主句动作前发生,只用 when.
①When he had finished his homework,he took a short rest.(finished先发生)当他完成作业后,他休息了一会儿.
②When I got to the airport,the guests had left.(got to后发生)当我赶到飞机场时,客人们已经离开了.
2.从句动作和主句动作同时发生,且从句动作为延续性动词时,when,while,as都可使用.
①When /While /As we were dancing,a stranger came in.(dance为延续性动词)当我们跳舞时,一位陌生人走了进来.
②When /While /As she was making a phonecall,I was writing a letter.(make为延续性动词)当她在打电话时,我正在写信.
3.当主句、从句动作同时进行,从句动作的时间概念淡化,而主要表示主句动作发生的背景或条件时,只能用 as.这时,as常表示“随着……”;“一边……,一边……”之意.
① As the time went on,the weather got worse.(as表示“随着……”之意)
② The atmosphere gets thinner and thinner as the height increases.随着高度的增加,大气越来越稀薄.
③As years go by,China is getting stronger and richer.随着时间一年一年过去,中国变得越来越富强了.
④The little girls sang as they went.小姑娘们一边走,一边唱.
⑤The sad mother sat on the roadside,shouting as she was crying.伤心的妈妈坐在路边,边哭边叫.
4.在将来时从句中,常用when,且从句须用一般时代替将来时.
①You shall borrow the book when I have finished reading it.在我读完这本书后,你可以借阅.
②When the manager comes here for a visit next week,Ill talk with him about this.下周,经理来这参观时,我会和他谈谈此事.
浏览量:2
下载量:0
时间:
下面是读文网小编整理的一些关于while 和 as在英语中的用法,欢迎大家阅读!
1. as...as的用法 as...as意为"和……一样",表示同级的比较。使用时要注意第一个as为副词,第二个as为连词。其基本结构为:as+ adj./ adv. +as。例如: (1)This film is as interesting as that one.这部电影和那部电影一样有趣。
其否定式为not as/so +adj./ adv. +as。例如: This dictionary is not as/so useful as you think.这本字典不如你想象的那样有用。 若有修饰成分,如twice, three times, half, a quarter等,则须置于第一个as之前。例如:
Your bag is twice as expensive as mine.你的袋子比我的贵一倍。
2. as用作连词引导时间状语从句,用as时,主句和从句的动作同时发生,强调伴随具有延续的含义。例如:
(1) You will grow wiser as you grow older.你会随着年龄的增长而越来越聪明。
3. as用作连词引导原因状语从句 as一般放在句首,语气较弱,较口语化(1) Since you are so sure of it he’ll believe you.既然你对此如此有把握,他会相信你的。 As rain has fallen, the air is cooler.因为下过雨,空气比较清爽。
4. as作连词引导让步状语从句 ,as含义是"虽然,尽管",所表示的语气较强,引导的让步状语从句用倒装语序
Strange as it may seem, nobody was injured in the accident.这次意外虽然显得令人不可思议,却没有人受伤。
二、as作关系代词的用法关系代词as引导定语从句时,既可以单独使用,也可以与其他词连用,
1. as引导定语从句与其他词连用
①用于the same...as结构中
This is the same book as I read last week.这本书和我上周读的那本是一样的。
②用于such...as结构中 I don”t like such books as he recommends.我不喜欢他推荐的那些书。
③用于"so +adj. + a/an + n. (单数) + as "结构中 I am not so strong a man as I was.我已经没有从前那么强壮了。
2. as单独引导定语从句 as单独引导定语从句时,先行词可以是一个词,也可以是一个句子或短语。例如:
She is late, as is often the case.她迟到了,这是经常的事。(先行词是整个主句)
She cooks as well as her mother does.她烧菜烧得跟她母亲一样好。
(2) To shut your eyes to facts, as many of you do, is foolish.对事实视而不见--你们好多人都是如此的愚蠢。(先行词是不定式短语)
三、as作介词的用法as作介词,意思是"作为","以……身份"。例如:
He came to China as a tourist five years ago.他五年前以游客的身份来过中国。
四、as作副词的用法"相同地","同样地"。例如:
They don’t have as many airplanes.他们没有同样多的飞机。
浏览量:2
下载量:0
时间:
下面是读文网小编为同学们整理了as作连词的用法 ,希望大家学以致用!
as作连词的用法:
1.作“在-------期间,当----的时候”引导时间状语从句.注意与when、 while的用法区别。
①下列情形时,只用as, 而不用when或while。
As a young man, he was active in sports.
②when作"当……的时候"解,可以指较短的(一点)时间,也可指一段时间。如:When I was at college, I could speak several foreign languages. When the clock struck twelve, I had slept for 2hours.
③ while常表示一段较长的时间或一个过程,强调主句谓语动词与从句谓语动词同时发生。如:Work while you work. Play while you play.
浏览量:2
下载量:0
时间:
下面小编给大家总结了英语连词的用法,希望对大家的英语学习有帮助。
1. —Oh, I failed again
—Don’t lose heart. One more effort, ________ you will succeed.
A. so that B. therefore C. however D. and
2. ________ a difficult situation, so you should send him a message and give him some advice.
A. As he is in B. He is in C. Being in D. He being in
3. She said she would work it out herself, ________ ask me for help.
A. and not to B. but not C. and prefer not D. rather than
4. ________ enough time, but I couldn’t do it better.
A. I was given B. Given C. To be given D. Though I was given
5. —How can I wake up so early?
—Set the alarm at 5 o’clock, ________ you’ll make it.
A. but B. or C. and D. so
6. For a person with reading habits, a printed page contains not only words ________ ideas, thoughts and feelings.
A. yet B. and C. or D. but
7. Information technology is taught in most schools, ________ we have entered the information society.
A. so B. while C. still D. for
8. English is understood all over the world ________ Turkey is spoken by only a few people outside Turkey itself.
A. while B. when C. if D. as
9. I was on the point of going to bed ________ Mr. Zhang rang.
A. as B. when C. while D. and
10. I asked him whether he had done all the work himself ________ whether he had had any assistance.
A. and B. but C. nor D. or
11. In some countries, ________ are called “public schools” are not owned by the public.
A. which B. as C. what D. that
12. ________ happens in the world makes us happy and sad by turns.
A. That B. What C. Which D. Whether
13. I read about this story in some book or other, does it matter ________ it was?
A. where B. what C. how D. which
14. One of the men present held the view ________ the book said was right.
A. what that B. what C. that D. that what
15. ________ I had walked for six hours, I was tired out.
A. After B. Before C. When D. As
16. Tom make up his mind to get a seat for the football match ________ it means standing in a queue all night.
A. as if B. as though C. even if D. whatever
17. The roof fell ________ he had time to dash into the house to save his baby.
A. as B. after C. until D. before
18. Doing your homework is a sure way to improve your test scores, and this is especially true ________ it comes to classroom tests.
A. as B. since C. when D. after
19. I have been keeping that photo ________ I can see it every day, as it always reminds me of my college days.
A. which B. where C. whether D. when
20. You may borrow this book ________ you promise to give it back.
A. in case B. so long as C. as if D. even if
【答案解析】
1. D. 考查“祈使句/名词+and+陈述句”句型。句意为:“再努力点,你就会成功的”。
2. B. so(因此)是并列连词,引出一个表示结果的分句,前面应是一个表示原因的分句,而无需再用连词,排除A;C和D又不是句子,也错了。
3. D. 因为rather than是对称连词,意为“而不”
4. A. 因为but是并列连词,后面是个句子,前面也一定是个句子,而不是一个分词短语或不定式短语,更不能再用连词though,所以排除B、C和D。
5. C. 考查“祈使句+and+陈述句”句型,意为“如果…就…”。虽然or也可用于此句型,但or是“否则、要不然”之意,如:Work hard, or you’ll fail. (努力学习,否则就会不及格。)
6. D. 因为not only…but (also)…是固定搭配7. D. 因为句中的并列连词for表示原因,是对前面分句所述内容的解释或补充说明。
8. A. 因为句中的并列连词while表示“对比或相反”。
9. B. 因为句中的并列连词when = just at that time, 意为“这时(突然)”。
10. D. 因为只有or才能表示选择,意为“(是…) 还是”。
11. C。本题考查what引导主语从句,并在主语从句中作主语。句意为“在许多国家,所谓的“公立学校”并非公众拥有。
12. B。本题考查引导主语从句的连接词。that引导主语从句只起连接作用,在从句中不作任何成分,无意义,但不能省略。what除引导主语从句外, 还在从句中作成分。which指一定范围内的“哪一个”;whether意为“是否”。根据句意“世上的事喜忧交替”可知答案为B13. D。该题考查宾语从句。可以看作是does it matter which book it was的省略。一定注意此题受母语干扰,很容易错选答案为A。只要抓住题干前一句I read about this story in some book or other的提示,就可知道是指一定范围内的“哪一个”,故答案为D。
14. D。that引导同位语从句;what the book said是同位语从句中的主语。
15. A。本题考查以after引导的时间状语从句,意为“在…之后”。句意为“步行了六小时后,我累坏了”。
16. C。even if=even though,引导的让步状语从句,意为“即使, 尽管”,符合题意。
17. D。本题考查before引导的时间状语从句,意为“在……之前”。句意为“他来不及冲进去救他的孩子,屋顶就塌了”。
18. C。When it comes to. . . 是一固定句型,意为“当谈到……时,涉及”。句意为“做作业是提高考分的一个可靠方法,这在涉及到课堂测验时尤其正确”19. B。该题考查where引导的地点状语从句,表示“在…地方”。句意为“我一直把照片放在我每天都能看到的地方,因为它总使我回想起大学里的日子”。
20. B。so long as=so long as, 意为“只要”,表示条件。句意为“只要你答应归还,你就可以把这书借走”。
浏览量:3
下载量:0
时间:
连词while除具有“当时”、“同时”等意义外,根据上下文还有以下不同含义及其不同译法。以下是小编为大家整理的while的翻译方法总结,希望能帮助大家更好地认识while这个单词,提高英语水平。
常放在句首,译作“尽管”、“虽然”,比although或 though语气要轻。例如:
1. While I believe it is true, I cannot prove it.
虽然我相信那是真的,但我无法证明。
2. While any kind of athletic shoe can provide a certain amount of rebound,
energy-return sneakers are designed to maximize this effect.
虽然任何一种运动鞋都能提供一定的反弹力,但回力运动鞋能够使这种效果最大化。
浏览量:2
下载量:0
时间:
It seems a gentleman had too much alcohol at a party, was heading home, and was pulled over by a state trooper. Upon being tested, the fellow couldn't walk a straight line any more than he could drive one, so the trooper wrote out a ticket and had just given it to the driver before an accident in the opposite lane took his attention to more important matters.
The inebriated driver, figuring that the trooper wasn't coming back to him, drove home and went to bed. he was awakened in the morning by a knock at the door, created by two more state troopers.
"Are you Mr. Johnson?" the asked? He admitted that he was.
"Were you pulled over at Main Street last night for driving under the influence?" Again, the man admitted that was he.
"And what did you do then," the troopers asked." The man replied that he drove his car home and went to bed.
"Where is your car now?" the troopers enquired. The man answered that it was in the garage.
"May we see the car?" asked the troopers. The man answered, "Sure," and opened the garage.
Inside the garage was the state troopers car.
浏览量:2
下载量:0
时间:
2016考研的考生早已投入了真正的紧张复习。阅读理解作为考研英语的重头戏,历届的考生都格外重视。现在来看我们的复习时间还有很多,但是按计划 英语一定要在基础阶段就打好坚实的基础,尤其是阅读理解真题的复习。那如何打好英语的基础,充分利用好阅读真题呢?
【例句】We have produced 20% more cotton this year than we did last year. 我们今年棉花产量比去年高百分之二十。
浏览量:2
下载量:0
时间:
While这个是英语学习中经常会遇到的,相信大家应该都不陌生,那么你清楚它的用法吗?下面读文网小编为大家总结while的几种常见的用法,欢迎大家一起学习。
1.Shelikestoliedownforawhileafterlunch.
她喜欢午饭后躺一会儿.
2.Comingtoanothercountrytostudyrequiresabigadjustmentandittakesawhiletofitin.
来到另一个国家求学,需要花一段时间来适应.
四.while,when,as的用法区别
都译为“当…的时候”,区别为:when后的从句谓语动词既可是延续性动词,也可是短暂性动词,而且还可作并列连词,译为“这时”.但以下句型一定用when,作并列连词:
句型A:was/weredoing…when…正在…这时(发生另一事)
句型B:beabouttodo…when…正要做…这时(发生另一事)
句型C:haddone…when…刚要做…这时(发生另一事)
1.Wewereabouttosetoutwhenitbegantorain.
我们刚要出发天突然下雨了.
2.IwaswalkingalongthebankoftheriverwhenIfellintoit.
我正沿河岸散步突然掉进水里.
3.Hehadhardlysatdownwhenhismobilerang.
他刚一坐下手机就响了.
while后的从句谓语动词只能是延续性动词,强调主从句的两个动词同时发生;while也可作并列连词,表示两个动作的对比,译为“而”“然而”.as则表示两个变化中的动作的同时性,译为“一边…一边…”.
1.Whilehismotherwascookinginthekitchen,theboyfellasleepinthechair.
(在一个延续动作过程中发生另一个动作)
2.Hehurriedhome,lookingbehindashewent.
他匆匆回家,边走边往后看.
浏览量:3
下载量:0
时间:
while表在…期间; 与…同时的意思,那么你知道while的同义词有哪些吗?接下来小编为大家整理了while的同义词,希望对你有帮助哦!
worth while (或 worth one's while)
1. 值得某人花时间(精力等)
浏览量:3
下载量:0
时间:
worthwhile表值得做的; 值得花时间的意思,那么你知道worthwhile的同义词有哪些吗?接下来小编为大家整理了worthwhile的同义词,希望对你有帮助哦!
1. It might be worthwhile to consider your attitude to an insurance policy.
考虑一下你对投保的看法也许有所助益。
2. The President's trip to Washington this week seems to have been worthwhile.
总统本周的华盛顿之行看来是有价值的。
3. The teacher recommended some really worthwhile novels to his students.
老师推荐给学生一些真正有价值的小说.
4. It would not prove worthwhile to instigate a nuclear attack.
挑起核攻击最终是不值得的.
5. It is worthwhile to note that both suffered persecution.
值得注意的是,双方都受到过迫害.
6. Is it worthwhile getting angry over such a trifling matter?
为这点小事犯得着生气 吗 ?
7. It isn't worthwhile spending so much time on minor problems.
在枝节问题上犯不着花这么多时间.
8. Teaching is a worthwhile calling.
教书是一种有价值的职业.
9. It is worthwhile doing it.
做这件事划算.
10. The trip is not worthwhile.
跑这一趟不值.
11. We believe the time and hard work involved in completing such an assignment are worthwhile.
我们认为完成这项任务所必须付出的时间与辛苦都是值得的。
12. If your water usage is very small it may be worthwhile opting for a meter.
要是用水量很小,就可以考虑装一个水表。
13. Their sobering conversation brought home to everyone present the serious and worthwhile work the Red Cross does.
他们发人深省的对话使在座的每个人都清楚地认识到红十字会所从事的严肃而有价值的工作。
14. We need to get rid of the idea that we must be liked all the time in order to beworthwhile.
我们必须抛弃那种认为要想活得有价值就得始终取悦他人的想法。
15. I am appalled that one so - called authority could castigate thousands of successful, worthwhile programs.
我感到震惊的是一个 所谓 的权威竟然能够苛刻地批评成千上万成功而有价值的节目.
worthwhile的同义词例句:
1. It is certainly worth checking up on your benefit entitlements.
查清楚你可以享受哪些福利是绝对有必要的。
2. By the time he's twenty he'll know everyone worth knowing in Washington.
到20岁时,他就会认识华盛顿所有值得认识的人。
3. Any coach worth his salt would do exactly as I did.
任何称职的教练都会采取和我一模一样的行动。
4. The directors of this company feel he's worth every penny.
这家公司的主管们觉得他值得栽培。
5. Customers are told what their policies will be worth on maturity.
客户被告知保险单到期时的价值。
6. It is worth pausing to consider these statements from Mr Davies.
戴维斯先生的这番话值得大家停下来思考一下。
7. The team would have need of a driver of his worth.
这支队伍需要一位他这样技术水平的司机。
8. "How many do you want?" — "I'll have a pound's worth."
“你要多少?”“我要1英镑的.”
9. Traditional Spanish food is delicious and its specialities are worth searching out.
传统的西班牙食品美味可口,其特色菜肴值得寻访。
10. Last year 400,000 acres of land yielded a crop worth $1.75 billion.
去年40万英亩的土地产值达17.5亿美元。
11. She needs to regain a sense of her own worth.
她需要重新认识到自我的价值。
12. A thousand pounds worth of jewellery and silver has been stolen.
价值1,000英镑的珠宝和银饰被盗。
13. They had shoplifted thousands of dollars' worth of merchandise.
他们已经偷了商店价值好几千美元的商品。
14. The baroque church of San Leonardo is worth a quick look.
圣莱昂纳多的巴洛克式教堂值得一看。
15. He had never had a woman of her worth as a friend.
他从来没有过像她这样值得交往的女性朋友。
1. Candidates deemed vote-worthy will be rewarded with campaign funds.
被认为有望获胜的候选人将会获得竞选资金。
2. The bank might think you're worthy of a loan.
银行也许会认为你具备贷款的条件。
3. They thought the feminist label was too worthy.
他们觉得女权主义者这个称谓太抬举她们了。
4. to be worthy of attention
值得注意
5. I did not esteem him to be worthy of trust.
我认为他不值得信赖.
6. There occurred nothing that was worthy to be mentioned.
没有值得一提的事发生.
7. They regard the problem as not worthy of serious consideration.
对这一问题他们都认为不屑一顾.
8. He is worthy of the title of labour hero.
劳动英雄的称号,他当之无愧.
9. His spirit of assiduous study is worthy of emulation.
他刻苦钻研的精神,值得效法.
10. I don't think I am worthy of such an honourable title.
这样的光荣称号,我可担当不起.
11. When we die for the people; it is a worthy death.
我们为人民而死, 就是死得其所.
12. This book is a monumental work worthy of China's new cultural movement.
这部著作不愧为中国新文化运动的丰碑.
13. To be candid with you, your son is far from trust worthy.
对你老实讲, 你的儿子是靠不住的.
14. This book is worthy of being read [ to be read ].
这本书 值得 一读.
15. He is worthy to have a place in the team.
他配成为该球队的队员.
浏览量:2
下载量:0
时间:
while有当 ... 的时候;虽然;尽管;然而等意思,那么你知道while的用法吗?下面跟着读文网小编一起来学习一下,希望对大家的学习有所帮助!
all the while
一直,始终from begin to end
He teaches English in the school all the while. 他一直在这所学校里教英语。
once in a while
时不时,偶尔,间或occasionally
He went to see them once in a while. 他偶尔去探望他们。
浏览量:1
下载量:0
时间:
浏览量:2
下载量:0
时间:
在C语言中,经常看到do...while(0)的宏,do...while(0)有很多作用,下面小编就为大家分享c语言里while的用法,希望对你有用。
1、避免goto语句:
通常,如果一个函数开始要分配一些资源,然后如果在中途遇到错误则要退出函数,当然,退出前要释放资源,我们的代码可能如下:
C代码
这里最大的问题是代码冗余,每增加一个操作,就要做相应的错误处理,非常不灵活,于是想到了一下的goto:
C代码
代码冗余是解决了,但是引入了C语言中比较微妙的goto语句,虽然正确的使用goto语句可以大大提高程序的灵活性与简洁性,但是会使我们的程序捉摸不定,为了既避免使用goto语句,又能消除代码冗余,可以考虑使用下面的 do...while(0):
C代码
2、避免空声明在编译时出现警告:
在linux内核源代码中,经常看到如下宏以避免在编译时出现警告:
#define FOO do { } while(0)
3、提供一个声明局部变量的基础块:
你可能经常会使用如下的宏:
#define exch(x,y) { int tmp; tmp=x; x=y; y=tmp; }
然而在某些情况下将会失效,下面的代码使用if...else...
if (x > y)
exch(x,y); https:// 分支 1
else
do_something(); https:// 分支 2
但是将被解释为一个分支的if语句:
if (x > y) {
int tmp;
tmp = x;
x = y;
y = tmp;
}
; https:// 空语句
else https:// ERROR!!!
do_something();
错误出在“;”直接位于代码块的后面,解决的办法是将代码嵌入do...while(0),于是得到下面的代码:
1 if (x > y)
2 do {
3 int tmp;
4 tmp = x;
5 x = y;
6 y = tmp;
7 } while(0);
8 else
9 do_something();
?于是上面的宏可以修改为:
1 #define exch(x,y) do {
2 int tmp;
3 tmp = x;
4 x = y;
5 y = tmp;
6 } while(0)
4、在条件语句中使用复杂的宏:
假如一个宏包含类似如下几行代码:
#define FOO(x)
printf("arg is %s", x);
do_something_useful(x);
现在想像一下下面的代码:
if (blah == 2)
FOO(blah);
这将解释为:
if (blah == 2)
printf("arg is %s", blah);
do_something_useful(blah);;
我们就会发现,if语句只作用于printf(), do_something_useful() 没按照愿意一起执行,即没有像你预期的那样被包含在if代码中,于是可以使用如下的代码块:
if (blah == 2)
do {
printf("arg is %s", blah);
do_something_useful(blah);
} while (0);
这样上面的宏就可以改为:
1 #define FOO(x) do {
2 printf("arg is %s", blah);
3 do_something_useful(blah);
4 } while (0)
PS:以上的第三种和第四种技巧,并不是唯一的方法,有同学留言说用其他的方法也可以实现,反而显得这样的宏定义过于花哨?事实并非如此,这样的宏定义在linux内核代码中非常常见,原因是代码简洁、通用、可移植性好
浏览量:3
下载量:0
时间:
浏览量:2
下载量:0
时间:
浏览量:2
下载量:0
时间:
meanwhile有其间;同时等意思,那么你知道meanwhile的用法吗?下面跟着读文网小编一起来学习一下,希望对大家的学习有所帮助!
1. Meanwhile, melt the white chocolate in a bowl suspended over simmering water.
同时,把碗置于微沸的水上,将白巧克力放入碗中使其熔化。
2. The media, meanwhile, has blown hot and cold on the affair.
同时,媒体对这件事的态度表现得忽冷忽热。
3. Meanwhile, sales of vinyl records halved in 1992 to just 6.7m.
与此同时,黑胶唱片的销售量在1992年下降了一半,只有670万张。
4. Meanwhile, Dusty Springfield's new TV series began a run on BBC 1.
同时,达斯蒂·斯普林菲尔德的电视剧新作开始在BBC1台播放。
5. Meanwhile, the domestic debate on Denmark's future role in Europe rages on.
与此同时,国内也展开了有关丹麦未来在欧洲扮演何种角色的激烈争论。
6. Meanwhile the race is on to resurface the road before next Wednesday.
与此同时正赶着在下周三之前把路面重新铺好。
7. You, meanwhile, will be skulking in the safety of the car.
与此同时,你会安全地藏在汽车里。
8. Meanwhile, back in London, Palace Pictures was collapsing.
与此同时,伦敦的皇宫影业公司也正在分崩离析。
9. Meanwhile, the boredom is excruciating.
同时,又无聊得让人苦恼不已。
10. Meanwhile the personality cult around this campaigner grew.
同时,对这位竞选者的个人崇拜正在逐渐升温。
11. The public, meanwhile, hold architects in low esteem.
与此同时,公众对建筑师并不看重。
12. Meanwhile, as the politicians haggle, the violence worsens.
在政客们大打嘴仗的同时,暴力事件愈演愈烈。
13. The doctor will see you again next week. Meanwhile, you must rest as much as possible.
医生下周还会给你看病。在此期间,你一定要尽可能多休息。
14. Meanwhile we must do a good job in transport and communications.
同时我们要搞好交通运输工作.
15. I continued working, meanwhile, he went out shopping.
我继续工作, 这期间他出去买东西.
浏览量:3
下载量:0
时间:
c语言中while的用法的用法你知道吗?下面小编就跟你们详细介绍下c语言中while的用法的用法,希望对你们有用。
while语句的一般形式为:
while(表达式) 语句
其中表达式是循环条件,语句为循环体。
while语句的语义是:计算表达式的值,当值为真(非0)时, 执行循环体语句。其执行过程可用下图表示。
【例6-2】用while语句计算从1加到100的值。用传统流程图和N-S结构流程图表示算法,见图:
01.#include <stdio.h>
02.int main(void){
03. int i,sum=0;
04. i=1;
05. while(i<=100){
06. sum=sum+i;
07. i++;
08. }
09. printf("%d",sum);
10. return 0;
11.}
【例6-3】统计从键盘输入一行字符的个数。
01.#include <stdio.h>
02.int main(void){
03. int n=0;
04. printf("input a string:");
05. while(getchar()!='') n++;
06. printf("%d",n);
07. return 0;
08.}
本例程序中的循环条件为getchar()!='',其意义是,,只要从键盘输入的字符不是回车就继续循环。循环体n++完成对输入字符个数计数。从而程序实现了对输入一行字符的字符个数计数。
使用while语句应注意以下两点。
1) while语句中的表达式一般是关系表达或逻辑表达式,只要表达式的值为真(非0)即可继续循环。
01.#include <stdio.h>
02.int main(void){
03. int a=0,n;
04. printf(" input n: ");
05. scanf("%d",&n);
06. while (n--) printf("%d ",a++*2);
07. return 0;
08.}
本例程序将执行n次循环,每执行一次,n值减1。循环体输出表达式a++*2的值。该表达式等效于(a*2; a++)。
2) 循环体如包括有一个以上的语句,则必须用{}括起来,组成复合语句。
浏览量:2
下载量:0
时间:
c中while的用法的用法你知道吗?下面小编就跟你们详细介绍下c中while的用法的用法,希望对你们有用。
while语句的一般形式为:
while(表达式) 语句
其中表达式是循环条件,语句为循环体。
while语句的语义是:计算表达式的值,当值为真(非0)时, 执行循环体语句。其执行过程可用下图表示。
【例6-2】用while语句计算从1加到100的值。用传统流程图和N-S结构流程图表示算法,见图:
01.#include <stdio.h>
02.int main(void){
03. int i,sum=0;
04. i=1;
05. while(i<=100){
06. sum=sum+i;
07. i++;
08. }
09. printf("%d",sum);
10. return 0;
11.}
【例6-3】统计从键盘输入一行字符的个数。
01.#include <stdio.h>
02.int main(void){
03. int n=0;
04. printf("input a string:");
05. while(getchar()!='') n++;
06. printf("%d",n);
07. return 0;
08.}
本例程序中的循环条件为getchar()!='',其意义是,,只要从键盘输入的字符不是回车就继续循环。循环体n++完成对输入字符个数计数。从而程序实现了对输入一行字符的字符个数计数。
使用while语句应注意以下两点。
1) while语句中的表达式一般是关系表达或逻辑表达式,只要表达式的值为真(非0)即可继续循环。
01.#include <stdio.h>
02.int main(void){
03. int a=0,n;
04. printf(" input n: ");
05. scanf("%d",&n);
06. while (n--) printf("%d ",a++*2);
07. return 0;
08.}
浏览量:2
下载量:0
时间: