Back to articles
Go Learning Notes - Part 2: Array, Slices, Loops & String Processing

Go Learning Notes - Part 2: Array, Slices, Loops & String Processing

via Dev.toKervie Sazon

Today I improved my Go Conference Booking App by learning how Go handles collections and loops. I explored arrays, slices, infinite loops, range, strings.Fields(), and the blank identifier. Here’s what I learned: Arrays (Fixed Size Collections) An array in Go has a fixed size. Example: var numbers [3]int = [3]int{10, 20, 30} Fixed length If I used an array for bookings, it would look like this: var bookings [50]string But this is limiting because: The size is fixed Harder to manage dynamic data That’s why slices are usually preferred. Slices (Dynamic Collections) Instead of using a fixed array, I used a slice to store bookings: bookings := []string{} Every time a user books: bookings = append(bookings, fName+" "+lName) What I Learned: Slices don’t have a fixed size append() adds new elements Slices are the most common way to manage lists in Go Infinite Loop I wrapped the booking logic inside an infinite loop: for { // booking logic here } Why? Allows multiple users to book tickets cont

Continue reading on Dev.to

Opens in a new tab

Read Full Article
27 views

Related Articles