This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
//imported the package fmt | |
import "fmt" | |
func main() { | |
// declare the variable with value = 10 and data-type int | |
var i int = 10 | |
// do loop execution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is how we declare the Boolean Varibales in go | |
// Here isMyNameHimanshu variable is declared specifing a data-type | |
var isMyNameHimanshu bool = true | |
// Here isMyNameHimanshu variable is declared without specifing a data-type | |
var isMyNameHimanshu = true | |
//here the varibale is declared without using the var keyword |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
//imported the package fmt | |
import "fmt" | |
func main() { | |
//main function gets called when the program runs | |
// declared the first variable with datatype int | |
var firstNumber int = 10 | |
// declared the second variable without any datatype |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
//imported the package fmt | |
import "fmt" | |
func main() { | |
//main function gets called when the program runs | |
// declared the first variable with datatype string | |
var firstName string = "Himanshu " | |
// declared the second variable without any datatype |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
//imported the package fmt | |
import "fmt" | |
func main() { | |
// we have declared an array with name "nameArray" of size 2 and data-type integer | |
var nameArray [2]string | |
//we assigned value Himanshu to the first element in the array nameArray |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
//imported the package fmt | |
import "fmt" | |
func main() { | |
//created a slice userdata with default value FirstName,SecondName and datatype string | |
var userData = []string{"FirstName", "SecondName"} | |
//print the default slice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
//Declared a map userData using the keyword `make` | |
var userData = make(map[int]string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
//imported the package fmt | |
import "fmt" | |
//main function gets called when the program runs | |
func main() { | |
//declared a variable with initial value = 0 | |
sum := 0 | |
//for loop initialization, with index<5 and incremented by one at a time using index ++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
//imported the fmt package | |
import "fmt" | |
//main function gets called when the program executes | |
func main() { | |
//we initialize the variable with value 2 and without any data-type | |
var i = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
//imported the fmt package | |
import "fmt" | |
//this is a function which returns a single maximum value | |
func maxValue(a, b int) int { | |
if a > b { | |
return a | |
} |