
[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.




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.


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.


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