博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java 循环控制
阅读量:4705 次
发布时间:2019-06-10

本文共 1322 字,大约阅读时间需要 4 分钟。

while 循环

while(condition){       //xxx}

1202026-20180604202354208-106644110.png


for循环

for(initialization;expression;update){//注意是分号的    //xxxx}      for(int x = 10; x < 20; x = x + 1) {         System.out.print("value of x : " + x );         System.out.print("\n");      }

1202026-20180604203124405-1137612559.png


do{    //xxxx}while(condition);int x = 10;      do {         System.out.print("value of x : " + x );         x++;         System.out.print("\n");      }while( x < 20 );

1202026-20180604203324495-1438378161.png


循环控制声明

break
1202026-20180604203527496-1007944168.png

int [] numbers = {10, 20, 30, 40, 50};      for(int x : numbers ) {         if( x == 30 ) {            break;         }         System.out.print( x );         System.out.print("\n");      }

continue

1202026-20180604203806813-839523802.png

int [] numbers = {10, 20, 30, 40, 50};      for(int x : numbers ) {         if( x == 30 ) {            continue;         }         System.out.print( x );         System.out.print("\n");      }

java 循环增强

for(declaration : expression) {   // Statements}public class Test {   public static void main(String args[]) {      int [] numbers = {10, 20, 30, 40, 50};      for(int x : numbers ) {         System.out.print( x );         System.out.print(",");      }      System.out.print("\n");      String [] names = {"James", "Larry", "Tom", "Lacy"}; //大括号      for( String name : names ) {         System.out.print( name );         System.out.print(",");      }   }}

1202026-20180604204317415-1393379659.png

转载于:https://www.cnblogs.com/cyany/p/9135383.html

你可能感兴趣的文章
Kali学习笔记39:SQL手工注入(1)
查看>>
C# MD5加密
查看>>
Codeforces Round #329 (Div. 2)D LCA+并查集路径压缩
查看>>
移动应用开发测试工具Bugtags集成和使用教程
查看>>
Java GC、新生代、老年代
查看>>
Liferay 6.2 改造系列之十一:默认关闭CDN动态资源
查看>>
多线程
查看>>
折线切割平面
查看>>
获取当前路径下的所有文件路径 :listFiles
查看>>
图像形态学及更通用的形态学的原理及细节汇总
查看>>
linux开启coredump的3种方法
查看>>
数据驱动之 python + requests + Excel
查看>>
小鸡啄米问题求解
查看>>
Castle.net
查看>>
HDU1532 网络流最大流【EK算法】(模板题)
查看>>
POJ 2594 Treasure Exploration (Floyd+最小路径覆盖)
查看>>
数字图像处理 博客目录索引
查看>>
nodejs+redis使用
查看>>
prime算法的使用
查看>>
【转】如何避免OOM总结
查看>>