3. Arrays, Slices, and Iteration
In this chapter, we cover the built-in list types: arrays
and slices
. Next, we move on to discussing Go’s for
keyword for iteration. Finally, we cover using the range
keyword to simplify iteration.
List Types: Arrays and Slices
Go has two built-in ordered list collection types: arrays and slices. Unlike other languages, there are no built-in complex list types such as linked lists1 or trees.2 Instead, Go uses the concept of composition3 to allow for creating more complex data structures, an example of which can be found with the list.List
4 type. We cover composition in more detail as we progress through this book.
1. https://en.wikipedia.org/wiki/Linked_list
2. https://en.wikipedia.org/wiki/Tree_%28data_structure%29 ...
Get Go Fundamentals: Gopher Guides now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.