Go Lang Tutorial: Conditions

Go Lang Tutorial: Conditions


Published at - Jan 11, 2022

GOLANG TUTORIAL SERIES

A switch statement allows you to compare a variable to a list of values for equality. Each value is referred to as a switch case, and each switch case is compared to the activated variable.Condition is a conditional statement that instructs the computer to perform a certain action if the condition is fulfilled.

The best course to learn Golang

What you will learn in this course

  • Build massively concurrent programs with Go Routines and Channels
  • Learn the advanced features of Go
  • Understand the differences between commonly used data structures
  • Prove your knowledge with dozens of included quiz questions
  • Apply Interfaces to dramatically simplify complex programs
  • Use types to future-proof your code and reduce the difficulty of refactors

If/Else in golang

In programming, this is a typical type of conditional statement that tells the computer to do something if the condition is true. If the condition is false, do something else.

if day == "sunday" || day == "saturday" {
rest()
} else if day == "monday" && isTired() {
groan()
} else {
work()
}

Statements in if in golang

In an if statement, a condition can be preceded by a declaration before a. The statement’s stated variables are only valid until the conclusion of the if.

if _, err := doThing(); err != nil {
fmt.Println("Uh oh")
}

Switch Case in golang

A switch statement enables a variable to be compared against a list of values for equality. Each value is referred to as a case, and each switch case is compared to the variable turned on.

switch day {
case "sunday":
// cases don't "fall through" by default!
fallthrough

case "saturday":
rest()

default:
work()
}

Click here for Golang tutorial series.

Thank you for reading this article, don’t forget to follow me to read more articles like this. You can also share this story with your friends if you find it helpful for others.

By evolving a Medium partner, you can support me and your other favored writers! 👇

Join Medium with my referral link - Harendra Verma

Learn More


Go Lang Tutorial: Conditions was originally published in Enlear Academy on Medium, where people are continuing the conversation by highlighting and responding to this story.





Follow Us

Follow us on facebook Click Here

Facebook QR
Scan from mobile
Join our telegram channel Click Here
Telegram QR
Scan from mobile