Loops II
for-in statement
Loops II
for-in statement
0
0
Checkbox to mark video as read
Mark as read

We've explored ForEach loop in previous articles, but this type of loop can only be used for load SwiftUI views, like rows in a list.

However, we may need to use loops in other situations. In this case we need to use a different variation, but the idea is the same:

let names: [String] = ["Pablo", "Andrea", "Clara", "Mateo"]

for name in names {
    print("My name is: \(name)")
}	

// My name is: Pablo
// My name is: Andrea
// My name is: Clara
// My name is: Mateo

name is declared as local variable that will contain each value of the array.



for i in 0..<10 {
    print("Number: \(i)")
}

// Number: 0
// Number: 1
// Number: 2
// Number: 3
// Number: 4
// Number: 5
// Number: 6
// Number: 7
// Number: 8
// Number: 9

course

Quiz Time!

0 Comments

Join the community to comment
Sign Up
I have an account
Be the first to comment

Accept Cookies

We use cookies to collect and analyze information on site performance and usage, in order to provide you with better service.

Check our Privacy Policy