java 中 for 与 while 比较。

来源:互联网 发布:python 创建嵌套字典 编辑:程序博客网 时间:2024/04/28 23:16
1、java 中的 for 循环:


int x = 1;


for(system.out.println("a");x<3; system.out.println("c"),x++)
{
    system.out.println("d");
}


输出结果为 
a
d
c
d
c




2、无限循环的最简单表现形式:


     for(;;){ }  /*for 中判读表达式中默认为true*/


     while(true){ }


3、java 中for 和 while 的区别


控制循环变量中的次数,只在循环体中使用则使用for更加优化内存,而控制循环次数的变量在循环体外部使用的则使用while。

0 0