YouTip LogoYouTip

Go Loops

# Go Loop Statements In many practical problems, there are many regular repetitive operations, so it is necessary to execute certain statements repeatedly in the program. The following is the flowchart for loop programs in most programming languages: !(#) Go provides the following types of loop processing statements: | Loop Type | Description | | --- | --- | | (#) | Executes a block of statements repeatedly | | (#) | Nesting one or more for loops within a for loop | * * * ## Loop Control Statements Loop control statements can control the execution process of statements within the loop body. GO supports the following loop control statements: | Control Statement | Description | | --- | --- | | (#) | Often used to interrupt the current for loop or exit a switch statement | | (#) | Skips the remaining statements of the current loop and proceeds to the next iteration of the loop. | | (#) | Transfers control to the labeled statement. | * * * ## Infinite Loop If the condition in a loop is never false, an infinite loop will occur. We can execute an infinite loop by setting only a condition expression in the for loop statement: ## Example package main import"fmt" func main(){ for true{ fmt.Printf("This is an infinite loop.n"); } }
← Android Broadcast ReceiversAndroid Eclipse β†’