Syntax

Swift For-In Loop Syntax

In Swift, for-in loop: loops over a range or collection — for i in 0..<10 { }

Quick Answer

Syntax
for i in 0..<10 { }
SwiftSyntax

For-In Loop

Code example
for i in 0..<10 { }

Loops over a range or collection.

Learn More

How to for-in loop in Swift

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

Swift For-In Loop Syntax

Use for i in 0..<10 { }.

Related Syntax References

Frequently asked questions

What is the Swift syntax for for-in loop?

Use this pattern: for i in 0..<10 { }

Can I copy this Swift code example?

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

Is this Swift syntax different on Mac or Windows?

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

Official source · How we verify