Back to questions
JuniorTheoryCommon
What does the program print?
package main
import "fmt"
func main() {
for i := 1; i <= 7; i++ {
if i%3 == 0 {
continue
}
fmt.Print(i)
}
}12457
- Expecting
12:continuedoes not leave the loop likebreak; it skips the rest of the current pass, so only 3 and 6 are left out. - Expecting
1245: the conditioni <= 7still holds for 7, so the last pass runs and prints it.
- What does the program print if
continueis replaced withbreak? - How would you make the loop stop after the first number greater than 4?