[Golang] Selection Of Conditions On Golang

Selection Condition is a condition needed to determine the program flow you want to use. this condition is needed in a system to control the running of the program.

It is the same as the traffic lights on the road. This light will regulate when the vehicle must stop and when the vehicle can return.

The selection condition function is like a traffic light, for example we want to display output A, we can use the selection when we will display output A and when we do not display output A.

Just like other programming languages, in Golang programming language, selection condition uses nested if, if..else and switch … case

A. Nested If

The code above is an example of a Nested If. which explains the condition if we input a value with a range of 80–100 then the cumlaude predicate will appear. but if we input a value of 50–79 it will display a good predicate.

Whereas if we enter a value less than that, the predicate does not pass, but if we input a value other than 0–100 it will display no predicate.

Condition if the value is between 10–49
Condition if the value is between 50–79
Condition if the value is between 80–100
Condition if the value is other than 0–100

B. If..Else

The code above is an example of if..else. Where if we input yes then the words “You are a female” will appear, but if we input no, the words “You are a male” will appear.

Condition if the value is Yes
Condition if the value is No

C. Switch..Case

The code above is an example of switch..case. Where if we input value 1 then January will appear, if we input value 2 then February will appear and so on. however, if we input a value outside of numbers 1–12, the month will not be found.

The default block is the same as else in the if condition. that is, if all cases are not met then the default block will be invoked.

Condition if the value is between 1–12
Condition if the value other than 1–12

In the go programming language, the switch state selection function is slightly different from other languages. if the case is fulfilled, it will not be checked to the next case. different from other programming languages, where if a case is met it will still be checked for the next case unless there is a code break.

At this point we finally know about the use of several selection conditions in the go programming language. then we can develop the use of selection conditions according to our needs




All about go language

Recommended from Medium

Developing a CRUD Node.js Application with PostgreSQL

Documentation-driven development: Or, why it’s time to revive the technical bookshelf

NEW eBook: Connecting Collaboration Platforms in the Age of Slack

Concept of Object Oriented Programming (OOPS)

Simple platformer controls in Unity

Edit existing FOREIGN KEY constraints in PostgreSQL with the ALTER TABLE command.

Sleep Process In Golang

One Tip to Crack the Coding Interview — Use Abstractions!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amiruddin Saddam

Amiruddin Saddam

Backend Engineer at Jamtangan.com And will always learn something new.

More from Medium

Echo 101: Get service metadata from Web UI

Responsive Terminal Applications in Golang

Blokhus Watch Tower

Pointer in Golang

Building basic micro-service with GoRilla