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⑧

    1.switch的表达式取值: byte  short  int  char   Enum(枚举)    jdk1.7版本以上支持 String类型 2. break: 01.代表跳出当前方法体!跳出 ...

  2. 前端vue项目-关于下载文件pdf/excel(三)

    最近在做一些需求,需要下载一些文件信息,最频繁的就是下载excel文件到本地了 看过了很多方法,做个整理吧哈哈哈哈 参考的文章链接: https://www.cnblogs.com/jiangweic ...

  3. tp配置

    <?php// +----------------------------------------------------------------------// | ThinkPHP [ WE ...

  4. springMvc 简单搭建

    1.pom.xml 依赖引入 2.配置web.xml 3.配置 springMvc.xml 4.配置 logback.xml 5.编写 controller 测试 1.pom.xml 依赖引入 < ...

  5. git 命令篇

    *利用命令在仓库新建文件 *远程克隆到本地 *查看子文件 *创建新的分支  合并分支 删除分支  *合并分支 冲突 当Git无法自动合并分支时,就必须首先解决冲突.解决冲突后,再提交,合并完成. 用g ...

  6. ES脑裂问题

    脑裂:一个集群中的不同节点对于集群的状态有了不一样的理解 ES集群的总体状态是red,本来9个节点的集群在结果中只显示4个节点在线: 正常情况下,集群中的所有节点应该对集群中的master的选择是一致 ...

  7. windwos7 vnc连接centos6.6

    一.先配置centos6.6的vnc(已经安装过桌面) #yum  install  fontforge -y   防止字体乱码 #yum tigervnc tigervnc-server -y   ...

  8. 关于selenium实现滑块验证

    关于selenium实现滑块验证 python2.7+selenium2实现淘宝滑块自动认证参考链接:https://blog.csdn.net/ldg513783697/article/detail ...

  9. [转]JavaScript与元素间的抛物线轨迹运动

    在张鑫旭的博客看到这个抛物线的小动画,觉得很感兴趣,转载一下方便研究~ 原文地址:http://www.zhangxinxu.com/wordpress/?p=3855 在页面上添加元素的位移动画,除 ...

  10. Oracle查看表或者视图的定义语句

    查看表的定义 SELECT DBMS_METADATA.GET_DDL('TABLE','TABLE_NAME') FROM DUAL; 查看视图的定义语句 SELECT DBMS_METADATA. ...