YouTip LogoYouTip

Go If Statement

# Go Language if Statement [![Image 4: Go Conditional Statements](#) Go Conditional Statements](#) An if statement consists of a Boolean expression followed by one or more statements. ### Syntax The syntax of an if statement in Go programming language is: if Boolean expression { /* Executes when the Boolean expression is true */ } If the Boolean expression evaluates to true, the block of code inside the if statement is executed. If it evaluates to false, the block is not executed. The flowchart is as follows: ![Image 5: Go if Statement](#) ### Example Use if to check the size of a number variable: ## Example package main import"fmt" func main(){ /* Define local variables */ var a int=10 /* Use if statement to check the Boolean expression */ if a <20{ /* If the condition is true, execute the following statement */ fmt.Printf("a is less than 20n") } fmt.Printf("a value is : %dn", a) } The output of the above code is: a is less than 20 a value is : 10 [![Image 6: Go Conditional Statements](#) Go Conditional Statements](#)
← Android Content ProvidersAndroid Services β†’