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


Prompt Examples

ChatGPT Prompt Examples

posted on 2023-06-21 22:37:19 - ChatGPT Tutorials


Use Cases

Chat GPT Key Use Cases

posted on 2023-06-21 21:03:17 - ChatGPT Tutorials


Prompt Frameworks

Prompt Frameworks

posted on 2023-06-21 19:33:06 - ChatGPT Tutorials