package main

import "fmt"

func main()  {
nums := []int{2,3,4}
sum :=0
//rang 遍历切片
for _,num := range nums {
sum += num
}
fmt.Println("sum:",sum) for i,num := range nums {
if num == 3 {
fmt.Println("index:",i)
}
} kvs := map[string]string{"a":"apple","b":"banana"} //range遍历map
for k,v := range kvs{
fmt.Printf("%s-> %s\n",k,v)
} //range遍历字符串
for i,c := range "go" {
fmt.Println(i,c)
}
//range还可以遍历channel
}

Go Example--range的更多相关文章

  1. SQL Server 合并复制遇到identity range check报错的解决

        最近帮一个客户搭建跨洋的合并复制,由于数据库非常大,跨洋网络条件不稳定,因此只能通过备份初始化,在初始化完成后向海外订阅端插入数据时发现报出如下错误: Msg 548, Level 16, S ...

  2. Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range

    在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...

  3. [LeetCode] Range Addition 范围相加

    Assume you have an array of length n initialized with all 0's and are given k update operations. Eac ...

  4. [LeetCode] Count of Range Sum 区间和计数

    Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Ra ...

  5. [LeetCode] Range Sum Query 2D - Mutable 二维区域和检索 - 可变

    Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...

  6. [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  7. [LeetCode] Range Sum Query 2D - Immutable 二维区域和检索 - 不可变

    Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...

  8. [LeetCode] Range Sum Query - Immutable 区域和检索 - 不可变

    Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...

  9. [LeetCode] Bitwise AND of Numbers Range 数字范围位相与

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  10. C++11中自定义range

    python中的range功能非常好用 for i in range(100): print(i) 现在利用C++11的基于范围的for循环特性实现C++中的range功能 class range { ...

随机推荐

  1. 深入理解 Java 虚拟机——走近 Java

    1.1 - 概述 Java 总述:Java 不仅是一门编程语言,还是一个由一系列 计算机软件 和 规范 形成的技术体系,这个技术体系提供了完整的用于软件开发和跨平台部署的支持环境,并广泛应用于 嵌入式 ...

  2. Gameobject.Find和Transform.Find应用区别

    using UnityEngine;using System.Collections; public class test : MonoBehaviour{ private GameObject ro ...

  3. python实现用户登录界面

    要求 输入用户名密码正确,提示登录成功, 输入三次密码错误,锁定账户. 实现原理: 创建两个文件accout,accout_lock accout记录用户名,密码 accout root 1qazxs ...

  4. 1.2socket服务器使用多线程

    socket服务器代码如下 # -*- coding: utf-8 -*-from socket import * import time import threading,_thread as th ...

  5. BootstrapValidator验证

    相关链接: https://www.cnblogs.com/wuwenshuai/p/7120755.html https://www.cnblogs.com/v-weiwang/p/4834672. ...

  6. DevExpress WPF v18.2新版亮点(五)

    买 DevExpress Universal Subscription  免费赠 万元汉化资源包1套! 限量15套!先到先得,送完即止!立即抢购>> 行业领先的.NET界面控件2018年第 ...

  7. 关于ArrayList中的iterator返回的事迭代器实例问题。

    Arraylist是一个具体的类,它并没有定义它自己的iterator()方法,,它只是从AbstractList 这个抽象类中继承了iterator()这个方法,而AbstractList 中的it ...

  8. HDU 2063 (二分图最大匹配)

    RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐.但是,每个女孩 ...

  9. 联想 Lenovo PWR-G60 无线掌中宝拆机

    从朋友那里弄了台Lenovo PWR-G60,现在已经停产了,淘宝上某店卖的国产WIFI Pineapple貌似就是拿这个刷的,打算出篇DIY教程 现在人在外地,编程器.热风枪.烙铁工具啥的都没有,更 ...

  10. ubantu 安装git

    1.安装git并配置 sudo add-apt-repository ppa:git-core/ppa sudo apt-get update sudo apt-get install git 可以使 ...