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

  • 相关阅读:
    前端 CSS 与HTML 学习笔记详细讲解
    Python-Django之DRF
    Flask
    flask
    Python
    Python爬虫
    前端开发规范
    为什么 [] == ![] 输出是true?
    javascript准确判断各种数据类型
    JavaScript数组扁平化常用方法总结
  • 原文地址:https://www.cnblogs.com/cyany/p/9135383.html
Copyright © 2020-2023  润新知