Go lang
Programs
read csv file
find variable type in golang
for loops in golang
MongoDB sort() Method
MongoDB Find
MongoDB FindOne
differences between arrays and slices
InsertOne MongoDB
Connecting to MongoDB
how to use range in golang
Modules
Create a Go module
Create app using Go Module
Install
Installing GO lang

how to use range in for loop - golang



Introduction

Here we are going to explain, usage of range on slices in for loop


usage of range on []int slice for loop

    // declare and init values in slice
    nums := []int{2, 3, 4}

    //iterate nums slice with range
    //i will have index and num will have value in index 
    for i, num := range nums {
        fmt.Printf("i=%d num=%d\n", i, num)
    }

output:

i=0 num=2
i=1 num=3
i=2 num=4

usage of range on map[string]string slice for loop

    //define map with data with key/value pairs
    map1 := map[string]string{"A": "Apple", "B": "Banana"}

    //iterates over key/value pairs
    for k, v := range map1 {
        fmt.Printf("%s -> %s\n", k, v)
    }

    //just on key
    for k := range map1 {
        fmt.Printf("key: %s value: %s\n", k, map1[k])
    }

output:

A -> Apple
B -> Banana
key: A value: Apple
key: B value: Banana


how to use range in golang

how to use range in golang

posted on 2022-05-03 08:28:11 - Go lang Tutorials


find variable type in golang

find variable type in golang

posted on 2022-05-03 05:24:55 - Go lang Tutorials


for loops in golang

for loops in golang

posted on 2022-05-03 04:27:40 - Go lang Tutorials


Run MongoDB On WSL Ubuntu

Run MongoDB On WSL Ubuntu

posted on 2022-04-28 05:02:09 - mongodb Tutorials


Installing MongoDB

Installing MongoDB

posted on 2022-04-28 04:16:57 - mongodb Tutorials


MySQL TRIGGERS

MySQL - Triggers

posted on 2019-11-29 21:44:07 - mysql Tutorials