Syntax

Go Range Loop Syntax

In Go, range loop: loops over a slice or map — for i, v := range items { }

Quick Answer

Syntax
for i, v := range items { }
GoSyntax

Range Loop

Code example
for i, v := range items { }

Loops over a slice or map.

Learn More

How to range 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 Range Loop Syntax

Use for i, v := range items { }.

Related Syntax References

Frequently asked questions

What is the Go syntax for range loop?

Use this pattern: for i, v := range items { }

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