Control Structures in Go

Control Structures in Go


Go has all the standard control structures found in most programming languages, including if/else statements, for loops, and switch statements.



if x < 0 {

    fmt.Println("Negative")

} else if x == 0 {

    fmt.Println("Zero")

} else {

    fmt.Println("Positive")

}


for i := 0; i < 10; i++ {

    fmt.Println(i)

}


switch day {

    case "Monday":

        fmt.Println("Today is Monday")

    case "Tuesday":

        fmt.Println("Today is Tuesday")

    default:

        fmt.Println("Today is another day")

}

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...