for-in Over Collections
Walk every item without an index.
Skip the Index
Often you just want each item, not its position. The for-in loop hands you items one at a time with no counter to manage. ✨
The for-in Shape
Write for, a variable name, the keyword in, then your collection. Each pass binds the variable to the next element.
for (var item in items) {
print(item);
}All lessons in this course
- The Classic for Loop
- while and do-while Loops
- for-in Over Collections
- break, continue, and Labels