create a loop from 1 to 100 in swift

To create a loop from 1 to 100 in Swift, you can use a for loop. The syntax for a for loop in Swift is as follows:

main.swift
for index in start...end {
    // code to repeat
}
51 chars
4 lines

To loop from 1 to 100, you can set the starting value of index to 1 and the ending value to 100:

main.swift
for index in 1...100 {
    // code to repeat
}
47 chars
4 lines

You can then add your desired code inside the curly braces {} to be executed in each iteration of the loop.

gistlibby LogSnag