YouTip LogoYouTip

Go Nested If Statements

# Go Language if Statement Nesting [![Image 3: Go Conditional Statements](#) Go Conditional Statements](#) You can embed one or more if or else if statements within an if or else if statement. ### Syntax The syntax for the if...else statement in the Go programming language is as follows: if boolean_expression_1 { /* Executes when boolean_expression_1 is true */ if boolean_expression_2 { /* Executes when boolean_expression_2 is true */ }} You can nest **else if...else** statements in the same way within an if statement. ### Example Using nested if statements: ## Example package main import"fmt" func main(){ /* Define local variables */ var a int=100 var b int=200 /* Check conditions */ if a ==100{ /* Executes if the if condition is true */ if b ==200{ /* Executes if the if condition is true */ fmt.Printf("a is 100, b is 200n"); } } fmt.Printf("a value: %dn", a ); fmt.Printf("b value: %dn", b ); } The result of the above code execution is: a is 100, b is 200 a value: 100 b value: 200 [![Image 4: Go Conditional Statements](#) Go Conditional Statements](#)
← Android Fragment TransitionsAndroid Single Fragment β†’