while、do...while、for循环的使用
来源:互联网 发布:淘宝运费险怎么用 编辑:程序博客网 时间:2024/04/30 03:58
class WhileDemo {
public static void main(String[] args){
/*
定义初始化表达式;
while(条件表达式){
循环体(执行语句);
}
int x = 1;
while(x<3){
System.out.println("x="+x);
x++;
}
int x = 1;
do{
System.out.println("do : x="+x);
x++;
}
while (x<3);
while(y<3){
System.out.println("y="+y);
y++;
}
/*
while:先判断条件,只有条件满足才执行循环体。
do while: 先执行循环体,在判断条件,条件满足,再继续执行循环体。
简单一句话:do while:无论条件是否满足,循环体至少执行一次。
*/
}
public static void main(String[] args){
/*
定义初始化表达式;
while(条件表达式){
循环体(执行语句);
}
int x = 1;
while(x<3){
System.out.println("x="+x);
x++;
}
int x = 1;
do{
System.out.println("do : x="+x);
x++;
}
while (x<3);
*/
while(y<3){
System.out.println("y="+y);
y++;
}
/*
while:先判断条件,只有条件满足才执行循环体。
do while: 先执行循环体,在判断条件,条件满足,再继续执行循环体。
简单一句话:do while:无论条件是否满足,循环体至少执行一次。
*/
}
}
class ForDemo {
public static void main(String[] args) {
/*
for(初始化表达式;循环条件表达式;循环后的操作表达式){
执行语句;
}
*/
for(int x = 0; x<3 ; x++){
System.out.println("x="+x);
}
//System.out.println("x===="+x);
int y=0;
while(y<3){
System.out.println("y="+y);
y++;
}
System.out.println("y===="+y);
/*
1,变量有自己的作用域。对于for来讲:如果将用于控制循环的增量定义在for语句中。那么该变量只在for语句内有效。
for语句执行完毕。该变量在内存中被释放。
2,for和while可以进行互换。如果需要定义循环增量。用for更为合适。
总结:
什么时候使用循环结构?
当要对某些语句执行很多次时,就使用循环结构。
*/
}
}
0 0
- while、do...while、for循环的使用
- while、do while、for循环
- 循环:for、while、do-while
- while循环、do..while 循环、for循环
- for循环,do....while循环,while循环
- for循环,while循环,do while循环
- C语言中循环结构语句 for循环及while,do--while 的使用
- java中循环命令while,for,do while的区别
- 循环语句For While do-while的小练习
- 对while、do while、for循环的理解
- For , while , do…while的死循环.
- While() , do{}while(); , for(){} 循环语句的用法
- while语句,do-while与for循环的介绍
- 循环控制 for while do while switch
- 循环语句小结 for while do-while
- while和do..while和for循环
- do... while,while and for 循环
- C#循环while、do...while、for、foreach
- 闰年判断
- [BZOJ 3156]防御准备(斜率优化DP)
- 命令行编译JNI
- FRID第二次作业第三题
- 2.multi-page editor的一些swt和swing组件之间的变换
- while、do...while、for循环的使用
- 服务器返回常见错误解码
- 分页和非分页内存
- poj 3669 BFS
- 学习笔记
- iOS开发中查看和删除cookies,设置指定的cookies
- "quals和==的区别"
- 用开源apidoc编写php接口文档,也可以编写其他语言apidoc安装使用
- 关于iOS开发过程中单元测试的一点拙见