第三章控制程序流程3.2.6(java编程思想第四版)(The third chapter control program flow 3.2.6 (Java programming thought Fourth Edition)).docVIP
- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
第三章控制程序流程3.2.6(java编程思想第四版)(The third chapter control program flow 3.2.6 (Java programming thought Fourth Edition))
第三章控制程序流程3.2.6(java编程思想第四版)(The third chapter control program flow 3.2.6 (Java programming thought Fourth Edition))
3.2.6 interrupts and continues
In any main part of the loop statement, break and continue can also be used to control the flow of the loop. Of which, break is used to force out of the loop and not execute the remaining statements in the loop. The continue stops performing the current iteration, then returns to the loop start and starts the new iteration.
The following program shows you the examples of break and continue in the for and while loops:
/ / BreakAndContinue.java
Break and continue keywords / / Demonstrates
Public, class, BreakAndContinue {
Public, static, void, main (String[], args) {
For (int, I = 0, I, 100, i++) {
If break (I = = 74); / / Out of for loop
If (I% 9! = 0 continue); / / Next iteration
System.out.println (I);
}
Int i = 0;
Infinite loop / / An:
While (true) {
I++;
Int j = I * 27;
If break (J = = 1269); / / Out of loop
If (I% 10! = 0 continue); / / Top of loop
System.out.println (I);
}
}
} / / /: ~
In this for loop, the value of I never reaches 100. Because once I reaches 74, the break statement interrupts the loop. Normally, you need to use break like this when you do not know when the interrupt condition is satisfied. As long as I cannot be divisible by 9, the continue statement causes the program flow to return to the beginning of the loop (so the I value is incremented). If divisible, the value is displayed.
The second part reveals a infinite cycle situation. However, there is a break statement inside the loop that stops the loop. In addition, youll see that continue moves back to the top of the loop and does not complete the remainder (so print the value only when the I value is divisible by 9). The output is as follows:
0,9,18,27,36,45,54,63,72,10,20,30,40,
The reason why 0 is displayed is that 0%9 equals 0.
The second form of an infinite loop is for (?;). The compiler sees while (true) as the same thing as for (()). There
您可能关注的文档
- 睡睡瘦(I lean).doc
- 睡神唐堂来分析失眠造就疲劳之旅(Tang Tanglai makes insomnia fatigue analysis of Morpheus trip).doc
- 睡觉不枕枕头有害健康(Sleeping without a pillow is bad for your health).doc
- 睡觉姿势不好可能导致颈椎病(Sleeping posture is bad, can cause cervical vertebra disease).doc
- 睡眠决定寿命 每天睡几个小时可长寿(Sleep determines life and sleeps a few hours a day for long life).doc
- 睡觉打呼噜可能更长寿(Sleep and snoring may be longer lived).doc
- 睡觉磨牙(Sleeping molar).doc
- 睡觉门道(Sleep doorway).doc
- 睡觉问题(Sleeping problem).doc
- 督脉腧穴及傍针刺配合电针治疗腰椎间盘突出症56例(Du Meridians and proximal needling plus 56 cases of lumbar disc herniation treatment).doc
- 第三章药效学(The third chapter is pharmacodynamics).doc
- 第三腰椎横突综合症(Third lumbar transverse process syndrome).doc
- 第三节 酶的固定化(The third section is enzyme immobilization).doc
- 第三节 溶解度(Third section solubility).doc
- 第三节冷伤(Third cold wounds).doc
- 第三节地图(Third section map).doc
- 第三节下尿路感染(Third lower urinary tract infection).doc
- 第三节声母汉语音节中开始的辅音成份。依汉语习惯,声母带简单...(Third section initial consonant the initial consonant element in Chinese syllable. According to the Chinese habit, the initial consonant is simple...).doc
- 第三节 神经调节与体液调节的关系(The relationship between third nerve regulation and humoral regulation).doc
- 第三节 涂料颜色的调配185(Third, paint color 185).doc
文档评论(0)