zoukankan      html  css  js  c++  java
  • for循环结构

    for循环结构:
    1.for(初始化; 布尔表达式; 更新) { //代码语句 }
     
    public class Test {
    public static void main(String args[])
    { for(int x = 10; x < 20; x = x+1) { System.out.print("value of x : " + x ); System.out.print(" "); } } }
     
    2.增强 for 循环语法格式如下
    for(声明语句 : 表达式) { //代码句子 }

    声明语句:声明新的局部变量,该变量的类型必须和数组元素的类型匹配。其作用域限定在循环语句块,其值与此时数组元素的值相等。

    表达式:表达式是要访问的数组名,或者是返回值为数组的方法
    package xunhuan;
    public class forxh {
           public static void main(String args[]) {
                int [] numbers = {10, 20, 30, 40, 50};
             for(int x : numbers ) {
                if( x == 30 ) { System.out.print("跳出循环");
                    
                         break;
                   
                     }
                     System.out.println( x );
                  
                  }
               }
            }
     
  • 相关阅读:
    05_python_字典
    04_python_列表
    03_python_基本数据类型
    02_python_while循环/格式化输出/逻辑运算
    01_python_初始python
    vue中v-model的数据双向绑定(重要)
    vue中轮播图的实现
    侦听器watch 监听单个属性
    vue computed监听多个属性
    vue中ajax应用
  • 原文地址:https://www.cnblogs.com/zhifeiji822/p/14600550.html
Copyright © 2011-2022 走看看