Syntax

Go For Loop Syntax

In Go, for loop: go's only loop keyword — for i := 0; i < 10; i++ { }

Quick Answer

Syntax
for i := 0; i < 10; i++ { }
GoSyntax

For Loop

Code example
for i := 0; i < 10; i++ { }

Go's only loop keyword.

Learn More

How to for loop in Go

  1. Open your Go file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Go For Loop Syntax

Use for i := 0; i < 10; i++ { }.

Related Syntax References

Frequently asked questions

What is the Go syntax for for loop?

Use this pattern: for i := 0; i < 10; i++ { }

Can I copy this Go code example?

Yes. Use Copy code and adapt the example to your program.

Is this Go syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify