...

Web Technologies - Go Language

Back to Course

Lesson Description


Lession - #357 GO-Loops


Go - Loops

There might be a circumstance, when you really want to execute a square of code a few number of times. As a rule, proclamations are executed consecutively: The main assertion in a capacity is executed first, trailed constantly, etc. Programming dialects give different control structures that consider more muddled execution ways.



Loop Type & Description

for loop

A for loop is additionally utilized as a limitless loop by eliminating every one of the three articulations from the for loop. At the point when the client didn't compose condition proclamation in for loop it implies the condition articulation is valid and the loop goes into a boundless loop.

nested loops

These are one or multiple loops inside any for loop.

Loop Control Statements

loop control statements change an execution from its not unexpected arrangement. Whenever an execution leaves its degree, all programmed objects that were made in that extension are obliterated.

Control Statement & Description

loop control statements change an execution from its not unexpected arrangement. Whenever an execution leaves its degree, all programmed objects that were made in that extension are obliterated.

break statemen

It terminates a for loop or change explanation and moves execution to the assertion promptly following the for loop or switch.

continue statement

It makes the circle skirt the rest of its body and promptly retest its condition preceding repeating.

goto statement

It transfers control to the labeled statement.

The Infinite Loop

A loop turns into an endless loop assuming its condition never turns out to be false. The for loop is customarily utilized for this reason. Since none of the three articulations that structure the for loop are required, you can make a perpetual loop by leaving the restrictive articulation unfilled or by passing consistent with it.

package main

import "fmt"

func main(>
{ for true { fmt.Printf("This loop will run forever.\n">
; } }