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. Python 中的 sys.argv 用法

    sys.argv是获取运行python文件的时候命令行参数 下面的代码文件是a.py,当我不用IDE工具,只用命令行窗口运行的时候,进入文件所在目录,输入:python a.py 输出结果如下 imp ...

  2. 三极管工作区在Spectre中的表示

    三极管的工作区在Spectre中通过静态工作点的region字段表示,具体表示如下: region: 0:off 1:fwd 2:rev 3:sat 4:breakdown 可在终端中输入 : ”sp ...

  3. Sql Server添加单引号

    " ' "(单引号)的运用:在sql server中,两个" ' "(单引号)在拼接字符串的情况下运用,就是表示拼接上了一个" ' "单引号 ...

  4. 【转】Ubuntu VI基本用法

    转自:http://blog.sina.com.cn/s/blog_4f3b79d0010166ai.html 1.vi的基本概念 基本上vi可以分为三种状态,分别是命令模式(command mode ...

  5. [Jobdu] 题目1499:项目安排

    题目描述: 小明每天都在开源社区上做项目,假设每天他都有很多项目可以选,其中每个项目都有一个开始时间和截止时间,假设做完每个项目后,拿到报酬都是不同的.由于小明马上就要硕士毕业了,面临着买房.买车.给 ...

  6. 在Mac OS X中使用mtr诊断路由节点问题

    这个工具是从阿里云客服那知道的,当时遇到阿里云CDN的一个节点出现丢包问题,用这个工具诊断路由节点问题. 1. 下载地址:http://rudix.org/packages/mtr.html(在园子里 ...

  7. Hadoop 新 MapReduce 框架 Yarn 详解【转】

    [转自:http://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop-yarn/] 简介: 本文介绍了 Hadoop 自 0.23.0 版本 ...

  8. [转]Understanding Weak References

    原文地址:https://weblogs.java.net/blog/enicholas/archive/2006/05/understanding_w.html 推荐另一篇文章:http://www ...

  9. RTX——第7章 任务管理

    以下内容转载自安富莱电子: http://forum.armfly.com/forum.php 单任务系统学习多任务系统之前,我们先来回顾下单任务系统的编程框架,即裸机时的编程框架. 裸机编程主要是采 ...

  10. uva10160(dfs+状态压缩)

    题意:给出n个点,以及m条边,这些边代表着这些点相连,修一个电力站,若在某一点修一个站,那么与这个点相连的点都可以通电,问所有的点都通电的话至少要修多少个电力站........ 思路:最多给出的是35 ...