Grokking Advanced Go
0% completed
Range over Integers and Functions
The two loops in the program below look almost the same. The first ranges over a slice, and the second ranges over a function named orderIDs. Both print order IDs and both stop at 1002.
Output:
slice loop: 1001 slice loop: 1002 iterator: start iterator: sending 1001 loop body: 1001 iterator: sending 1002 loop body: 1002 iterator: told to stop after loop
The slice loop prints only its own lines. The second loop is different, because the output alternates between orderIDs and the loop body. Its break also ended the for loop inside `orderIDs
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%