The for statement can be used to conveninently iterate over the elements of an array. The general syntax of the array-based for statement is:

    for (type variable : array) {
body-code
}

The array-based for statement has four parts. The array is an expression that returns an array. The type specifies the type of variable which will be used to hold elements from the array. In particular, variable always holds the current element of the iteration and can be used by the code in body-code. body-code is code that will be executed once for every element in the array. Here is an example of the for statement.

    // Returns the smallest integer in the supplied array
public int getMin(int[] ints) {
int min = Integer.MAX_VALUE;
for (int num : ints) {
if (num < min) {
min = num;
}
}
return min;
}
Related Examples

e1087. 用For循环做数组的遍历的更多相关文章

  1. 初识Javascript.03 -- switch、自增、while循环、for、break、continue、数组、遍历数组、合并数组concat

    除了注意大小写,别的木啥了 Switch语句 Switch(变量){ case 1: 如果变量和1的值相同,执行该处代码 break; case 2: 如果变量和2的值相同,执行该处代码 break; ...

  2. Java-在数组中遍历出最值

    在操作数组时,经常需要获取数组中元素的最值. 代码 public class Example31{ public static void main(String[] args){ int[] arr= ...

  3. swift基本用法-for循环遍历,遍历字典,循环生成数组

    // Playground - noun: a place where people can play import UIKit //--------------------------------- ...

  4. swift-for循环遍历,遍历字典,循环生成数组

    // Playground - noun: a place where people can play import UIKit //--------------------------------- ...

  5. 指针数组的初始化和遍历,并且通过for循环方式、函数传参方式进行指针数组的遍历

    /************************************************************************* > File Name: message.c ...

  6. Android java程序员必备技能,集合与数组中遍历元素,增强for循环的使用详解及代码

    Android java程序员必备技能,集合与数组中遍历元素, 增强for循环的使用详解及代码 作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 For ...

  7. 循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate)的区别

    表示“重复”这个含义的词有很多, 比如循环(loop), 递归(recursion), 遍历(traversal), 迭代(iterate). 循环算是最基础的概念, 凡是重复执行一段代码, 都可以称 ...

  8. JavaScript循环和数组常用操作

    while循环 语法: do while循环 语法:do{循环体}while(条件表达式); 特点:do while循环不管条件是否成立,无论如何循环体都会执行一次. 使用场合:用户输入密码,如果密码 ...

  9. JavaScript中数组中遍历的方法

    前言 最近看了好几篇总结数组中遍历方法的文章,然而"纸上得来终觉浅",决定此事自己干.于是小小总结,算是自己练手了. 各种数组遍历方法 数组中常用的遍历方法有四种,分别是: for ...

随机推荐

  1. mysql分组取每组前几条记录(排序)

    首先来造一部分数据,表mygoods为商品表,cat_id为分类id,goods_id为商品id,status为商品当前的状态位(1:有效,0:无效). CREATE TABLE `mygoods` ...

  2. session和cookie的联系

    前提: 一.cookie机制 正统的cookie分发是通过扩展HTTP协议来实现的,服务器通过在HTTP的响应头中加上一行特殊的指示以提示浏览器按照指示生成相应的cookie.然而纯粹的客户端脚本如J ...

  3. Android Hawk数据库 github开源项目

    Android Hawk数据库 github开源项目 Hawk 是一个很便捷的数据库  . 操作数据库仅仅需一行代码 , 能存不论什么数据类型 . github 地址: https://github. ...

  4. cv1.0入门

    作者 群号 C语言交流中心 环境 VS2010UltimTrial1.iso                    http://pan.baidu.com/s/1dEL85kl VS2010Ulti ...

  5. nginx + django on windows

    It's quite simple to run django on nginx on windows. Here are some key steps to follow - 1. Download ...

  6. Java 并发多线程处理优秀博文整理

    多线程(11)-Fork/Join-Java并行计算框架 推荐理由:Java在JDK7之后加入了并行计算的框架Fork/Join,本文是对其讲解 分解和合并:Java 也擅长轻松的并行编程! 推荐理由 ...

  7. 代码二次封装-xUtils(android)

    通常我们会引用很多lib 而且会出现lib 与我们的功能仅仅差一点点 这种情况我们最好不要去改动源代码 而是进行二次封装 举例我使用 xUtils的二次封装 此处说明我是搞ios的 这个是androi ...

  8. ssh 远程执行命令 -t

    # ssh -p22022 -t 122.16.67.116 ls -l /root/.ssh total -rw-r--r-- root root Jan : authorized_keys -rw ...

  9. springboot获取URL请求参数的多种方式

    1.直接把表单的参数写在Controller相应的方法的形参中,适用于get方式提交,不适用于post方式提交. /** * 1.直接把表单的参数写在Controller相应的方法的形参中 * @pa ...

  10. 深入理解Eureka - Eureka Client获取注册信息机制

    深入理解Eureka - Eureka Client获取注册信息机 Eureka Client提供了定时获取注册信息的机制.Eureka Client获取注册信息的所有逻辑都在DiscoveryCli ...