Go TutorialLesson 15Free preview
Go Loops
This lesson is part of Go · All levels
Summary
This lesson shows that Go has only one loop keyword, which is for. For can be used with three classical parts (init; condition; post), only with condition, or without condition at all as an infinite loop. Break stops the iteration and continue to jump to the next iteration, both of which are important to control the repetition flow.
Key points
- For is the only repetition structure in Go
- Three forms for: for i: = 0; i < n; i++ {}, for condition {}, and for {}
- Break out of the loop; continue on to the next iteration
- For range is used to iterate arrays, slices, maps, and strings
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.