a for loop of strings in swift

To iterate over a collection of strings using a for loop in Swift, you can follow these steps:

  1. Define an array with a list of strings.

  2. Use the for-in loop to iterate over the array of strings, as follows:

main.swift
let strings = ["apple", "banana", "orange"]
for string in strings {
    print(string)
}
88 chars
5 lines

In the above code, we first define an array called strings containing a list of strings. Then, we use a for-in loop, which iterates over each string in the strings array and prints it to the console.

You can modify the loop to perform other operations on the strings, depending on your use case.

gistlibby LogSnag