loop for swiftui code example
Example 1: swift for loop
for n in 1...5 {
print(n)
}
Example 2: for in swiftui
struct ContentView: View {
let colors: [Color] = [.red, .green, .blue]
var body: some View {
VStack {
ForEach(colors, id: \.self) { color in
Text(color.description.capitalized)
.padding()
.background(color)
}
}
}
}