zoukankan      html  css  js  c++  java
  • java 循环控制

    while 循环

    while(condition){
           //xxx
    }
    


    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("
    ");
          }
    


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


    循环控制声明
    break

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

    continue

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

    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("
    ");
          String [] names = {"James", "Larry", "Tom", "Lacy"}; //大括号
    
          for( String name : names ) {
             System.out.print( name );
             System.out.print(",");
          }
       }
    }
    

  • 相关阅读:
    springboot整合springmvc原理
    springboot Thymeleaf
    springboot 首页处理
    springboot整合Druid
    springboot 整合JDBC
    CentOS安装Mysql
    springboot 多环境切换
    springboot JSR303数据校验
    【转载】WEB架构师成长之路
    一些想法
  • 原文地址:https://www.cnblogs.com/cyany/p/9135383.html
Copyright © 2011-2022 走看看