Swift - Loops
You want to print all even numbers from 1 to 10 but skip printing 6. Which Swift code snippet correctly uses
continue and break to achieve this?continue and break to achieve this?continue to skip printing 6 inside even number check, which is correct. for i in 1...10 {
if i == 6 {
break
}
if i % 2 == 0 {
print(i)
}
} breaks loop at 6, stopping early. for i in 1...10 {
if i == 6 {
continue
}
print(i)
} skips 6 but prints odd numbers. for i in 1...10 {
if i % 2 == 0 {
if i == 6 {
break
}
print(i)
}
} breaks inside even check, stopping early.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions