Skip to content

Instantly share code, notes, and snippets.

View hi-manshu's full-sized avatar

Himanshu Singh hi-manshu

View GitHub Profile
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 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
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
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
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
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
package main
import (
"fmt"
)
func main() {
//Declared a map userData using the keyword `make`
var userData = make(map[int]string)
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 ++
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
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
}