- 1、本文档共22页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
java循环语句(国外英文资料)
java循环语句(国外英文资料)
The Java looping statement has for, while, and do-while. These statements create what we usually call loops. You may know that a cycle repeats the same set of instructions until an end condition appears. As you will see, Java has a loop structure that is suitable for any programming.
5.2.1 while statements
The while statement is the most basic loop in Java. When its control expression is true, the while statement repeats a statement or statement block. Its general format is as follows:
While (condition) {
/ / the body of the loop
}
Condition condition can be any Boolean expression. As long as the conditional expression is true, the loop body is executed. When condition condition is false, program control is passed to the statement line following the loop. Curly braces are not necessary if only a single statement needs to be repeated.
The while loop below starts the subtracting count from 10 and prints 10 tick lines.
/ / Demonstrate the while loop.
The class While {
Public static void main (String args [])
Int n = 10;
While (n 0)
( tick + n);
N --;
}
}
}
When you run this program, it tick 10 times:
Tick ten
Tick 9
Tick eight
Tick 7
Tick 6
Tick 5
Tick 4
Tick 3
Tick 2
Tick 1
Because the while statement computes the conditional expression at the beginning of the loop, if the condition is false at first, the loop will not execute once. For example, in the following program, the call to println () has never been executed:
Int a = 10, b = 20;
While (a b)
A. out.println ( This will not be displayed );
The while loop (or any other loop in Java) can be empty. This is because a null statement (a statement consisting only of a semicolon) is legal in Java syntax. For example, the following program:
/ / The target of a loop can be empty.
The class NoBody {
Public static void main (String args [])
Int I, j;
I = 100;
J = 200;
/ / find midpoint between I and j
While (+ + I - j); / / no body in this loop
(1) the Midpoint is Midpoint is.
}
}
The program finds the m
您可能关注的文档
- AutoCAD文字输入全攻略(国外英文资料).doc
- C 各大有名库的介绍(国外英文资料).doc
- After Effect菜单中英文对照(国外英文资料).doc
- C Primer Plus 第八章 编程练习(国外英文资料).doc
- c 第4讲 流程图 if which(国外英文资料).doc
- C++ Primer Plus编程练习-第七章(国外英文资料).doc
- c++ 运算符重载-集合运算(国外英文资料).doc
- BIOS方式安装、引导GPT分区单硬盘中的win7和win8系统问题(国外英文资料).doc
- c++程序设计课后习题第6章答案(国外英文资料).doc
- C++第二章习题解答(国外英文资料).doc
文档评论(0)