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. Ubuntu下设置环境变量

    Ubuntu下设置环境变量有三种方法,一种用于当前终端,一种用于当前用户,一种用于所有用户:   一:用于当前终端: 在当前终端中输入:export PATH=$PATH:<你的要加入的路径&g ...

  2. 如何用 LaTeX 撰写博士学位论文?

    如何用 LaTeX 撰写博士学位论文? 序 一直觉得有必要写这样一篇文章,因为学位论文从格式上说更像一本书,与文章 的排版不同,不仅多出目录等文章没有的部分,而且一般要设置页眉页脚方便阅 读查找.学校 ...

  3. 安装perl的版本控制器perlbrew

    perlbrew可以用源码方式安装perl的各种版本,可以容纳多个perl版本共存,并随意切换. 1.把perlbrew安装到home目录: curl -L https://install.perlb ...

  4. vim打造简易C语言编辑器(在用2016.7.10)

    vim和C语言都需要长期的学习,才能够精通,我制作了这个简单的笔记,主要的作用是,不要在重复的,反复的找同一样东西了,积累是成功的关键. 1. 安装pathogen插件管理器. 在官网下载pathog ...

  5. [na]诺顿ghost磁盘对刻(备份系统分区或数据分区)

    一 诺顿ghost简介 ,可以克隆分区 也可以克隆磁盘 ,克隆成img或磁盘内容对刻 ,磁盘分区--img---磁盘分区 磁盘---磁盘 二 操作步骤 对刻好的系统 整体思路: ,A是模板机,A有C ...

  6. 告诉你38个MySQL数据库的小技巧

    无论是运维.开发.测试,还是架构师,数据库技术是一个必备加薪神器,那么,一直说学习数据库.学MySQL,到底是要学习它的哪些东西呢? 1.如何快速掌握MySQL? 培养兴趣 兴趣是最好的老师,不论学习 ...

  7. ubantu下安装软件

    Linux系统中,软件通常以源代码或者预编译包的形式提供.(1)软件源代码需要编译为二进制的机器代码才能够使用,安装比较耗时,不过您可以自行调节编译选项,决定需要的功能或组件,或者针对硬件平台作一些优 ...

  8. Echarts的option中的data问题

    option = { title : { text: '某站点用户访问来源', subtext: '纯属虚构', x:'center' }, tooltip : { trigger: 'item', ...

  9. java 监听器实现原理

      实例二: @Override public void onStart(Intent intent, int startid) { super.onStart(intent, startid); l ...

  10. PHP 友好的dump

    /** * 浏览器友好的变量输出 * @param mixed $var 变量 * @param boolean $echo 是否输出 默认为True 如果为false 则返回输出字符串 * @par ...