Java Note - Controlling Execution
2015-06-07 17:24
423 查看
Most procedural programming languages have some kind of control statement, and there is often overlap among languages.
True or False
All conditional statements use the truth or falsehood of a conditional expression to determine the execution path.
Java does not allow you to use a number as a boolean.
Selection
The basic way to control program flow is selection
Iteration
Looping is controlled by while, do-while and for, which are sometimes classified as iteration statements.
A statement repeats until the controlling boolean-expression evaluates to false.
Several keywords represent unconditional branching, which simply means that the branch happens without any test.
The comma operator
The comma operator has only one use in Java: in the control expression of a for loop
Using the comma operator, you can define multiple variables within a loop statement, but they must be of the same type
True or False
All conditional statements use the truth or falsehood of a conditional expression to determine the execution path.
Java does not allow you to use a number as a boolean.
Selection
The basic way to control program flow is selection
// select an execute path according to boolean expression if (boolean-exp) statement else statement // select from among pieces of code based on the value of an expression switch (exp) case (val_1) : statement_1; break; case (val_2) : statement_2; break; default statment_default; break;
Iteration
Looping is controlled by while, do-while and for, which are sometimes classified as iteration statements.
A statement repeats until the controlling boolean-expression evaluates to false.
// the most common loop syntax while (boolean-exp) statement // at least execute once do statement while (boolean-exp) // be used for counting for (initialization; boolean-exp; step) statement // Foreach syntax for (type t : iterable-object) statement
Several keywords represent unconditional branching, which simply means that the branch happens without any test.
return - cause the current method to exit and specify what value the method return break - quit the loop without executing the rest of the statements continue - stop the execution of the current iteration and begin the next iteration (label:) - the only place a lable is useful in java is right before an iteration statement
The comma operator
The comma operator has only one use in Java: in the control expression of a for loop
Using the comma operator, you can define multiple variables within a loop statement, but they must be of the same type
for (int i=0, j=0; i < 10; i++, j=i*2) statement
相关文章推荐
- Java for LeetCode 200 Number of Islands
- 毕向东day01笔记--dos-jdk-jre-环境变量等
- 关于MyEclipse的工程前面的红色感叹号的问题
- java类初始化顺序
- Java for LeetCode 199 Binary Tree Right Side View
- eclipse快捷键设置问题
- Java安全之数字证书
- JavaWeb学习总结(五十)——文件上传和下载
- JAVA IO流
- HDU-1039-Easier Done Than Said?(Java && 没用正则表达式是我的遗憾.....)
- 栈的应用1——判断java语句是否合法
- java重写equals方法需要注意的几点
- 【struts】struts初始化主线
- HotSpotVM的Java堆实现浅析#1:初始化
- 二叉查找树的查找、插入和删除 - Java实现
- 【JAVA进阶】——myEclipse连接mysql启动数据库服务
- eclipse使用笔记
- 跟择善老师系统学习JAVA(一)
- JAVA正则表达式 Pattern和Matcher
- Spring学习笔记 AOP开发