GoLang

Explain the Decision Making in Go Programming Language | Go Programming Tutorial

Explain the Decision Making in Go Programming Language | Go Programming Tutorial

Explain the Decision Making in Go Programming Language | Go Programming Tutorial

In this article, you will learn the following:

  • What are decision-making statements?
  • Types of decision-making Statements

What are decision-making statements?

The way people make decisions in real life works similarly in the programming language also which is called decision-making statements. When a piece of code is executed, when it fulfills the given condition in the decision making. It is also called control flow statements. It uses a control statement to control the flow of execution of the program based on certain conditions. 

Types of Decision-Making Statements:

  • If statement: It is a simple decision-making statement. It is used to decide whether a certain statement or block of statements will be executed or not. If the condition is true, it returns the statements in the block. 

SYNTAX:

If condition {

   // statement to execute only the given condition is true

}

    • If-else statement: In the decision-making statement, it has two parts i.e if and else. If the given condition is true, it will execute the set of statements, and if the condition is false, it will execute the set of statements written in the else block.

SYNTAX:

If condition

{ 

    // block of statement is executed only if the given condition is true

}

else

{

    // set of statement

}

  • Nested if statement: Go language has nested if statement. In this, nested if is an if statement that is the target of another if or else. It means if one statement is inside another if statement.

SYNTAX:

If condition1 {

 // executes the statements if the condition is true.

       If condition2 {

        // executes the statement if the condition is true.

}

}

  • If..else..if ladder: In this, there are multiple if-else statements. The if the statement has multiple if and else statements inside it. When the if statement is true it goes on and if the else statement is found then it will execute the else statement.
Yamini  Sharma

I am working as a professional engineer in "HIghRadius Technologies Pvt. Ltd." Passionate about learning and exploring new technologies. Enthusiast in writing and sharing what I have in my knowledge bucket.