Saved Bookmarks
| 1. |
What is the syntax used for the for loop in Golang? Explain. |
|
Answer» Go language follows the below syntax for implementing for loop. for [condition | ( init; condition; increment ) | Range] { statement(s); //more statements}The for loop works as follows:
Consider an EXAMPLE for for loop. The following code prints numbers from 1 to 5. package mainimport "fmt"func main() { // For loop to print numbers from 1 to 5 for j := 1; j <= 5; j++ { fmt.Println(j) }}The output of this code is: 12345 |
|