golang tutorial - Go Lang If | if - if else - switch - go programming - golang - go programming language - google go - go language - go program - google language
Golang If
- Decision making is used to specify the order in which statements are executed. In this tutorial, you will learn to create decisions using different forms of if...else statement.
- Go programming language provides following types of decision making statements.
Statement | Description |
---|---|
if statement | The if statement evaluates the test expression inside the parenthesis. If the test expression is evaluated to true (nonzero), statements inside the body of if is executed. If the test expression is evaluated to false (0), statements inside the body of if is skipped from execution |
if...else statement | An if statement can be followed by an optional else statement, which executes when the boolean expression is false. |
nested if statements | You can use one if or else if statement inside another if or else if statement(s). |
switch statement | A switch statement allows a variable to be tested for equality against a list of values. |
select statement | A select statement is similar to switch statement with difference as case statements refers to channel communications. |
golang , gopro , google go , golang tutorial , google language , go language , go programming language
C if statement
- The if statement evaluates the test expression inside the parenthesis.
- If the test expression is evaluated to true (nonzero), statements inside the body of if is executed.
- If the test expression is evaluated to false (0), statements inside the body of if is skipped from execution.
Flowchart of if statement
C if...else statement
- The if...else statement executes some code if the test expression is true (nonzero) and some other code if the test expression is false (0).
Syntax of if...else
- If test expression is true, codes inside the body of if statement is executed and, codes inside the body of else statement is skipped.
- If test expression is false, codes inside the body of else statement is executed and, codes inside the body of if statement is skipped.
Flowchart of if...else statement
golang , gopro , google go , golang tutorial , google language , go language , go programming language
Nested if...else statement (if...elseif....else Statement)
- The if...else statement executes two different codes depending upon whether the test expression is true or false. Sometimes, a choice has to be made from more than 2 possibilities.
- The nested if...else statement allows you to check for multiple test expressions and execute different codes for more than two conditions.
Syntax of nested if...else statement
FlowChart for Nested If Else Statment
If Loops in Go programming Language
golang , gopro , google go , golang tutorial , google language , go language , go programming language
Output of the above go program
Go by Example: Switch case in go language programming
- Switch statements express conditionals across many branches.