Go Loops - Go (programming language)

Sometimes a block of codes need to be executed several number of times. The statements are executed sequentially; the first statement is executed first and then the second one.

A statement or group of statements is enabled to execute multiple times by a loop statement. The general type of loop statement used in most of the programming languages is:

Loop Architecture

What are the types of loops supported by Go programming Language?

The types of loops supported by Go programming language are as follows. Click on the names to know about them in detail.

Loop Type

Description

for loop

Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable.

nested loops

You can use one or more for loop inside any for loop.

What are Loop Control Statements in Go Language?

The execution of the statements is changed from the normal sequence by the loop control statements. When a scope is left by the execution, the automatic objects which are created in the scope will get destroyed.

The control statements supported by C language are as follows. Click on the names to know more about them.

Control Statement

Description

break statement

Terminates thefor looporswitchstatement and transfers execution to the statement immediately following the for loop or switch.

continue statement

Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.

goto statement

Transfers control to the labeled statement.

Define Infinite Loop in Go Language

If the condition never turns to false, then the loop becomes infinite loop. Here, for loop is usually used. An endless loop can be made by leaving the conditional expression empty or pass true to it.

It is assumed to be true when the conditional expression is absent. An initialization and increment expression can be used but C programmers commonly use the for(;;) construct to signify an infinite loop.

Note: Infinite loop can be terminated by pressing Ctrl + C keys.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Go (programming language) Topics