Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift Basics (retired) Control Flow While and Do-While Loop

Brian Uribe
Brian Uribe
3,488 Points

I don't even know where to start.

This is so frustrating, I'm looking at this and my mind is just blanking.

while_loops.swift
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

1 Answer

Hi Brian!

Don't worry, it is quite normal when you are learning something new to feel a bit overwhelmed. What you are looking at there is like a variable except it can hold more than one value. This is called an Array.

The array in your code is called numbers and it contains all of the following values: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.

So, using the array name 'numbers' you can access any of those values. For example, if you wanted to access the number 1, right at the beginning of the Array, you would use the following code:

numbers[0]

The reason you would use the number 0 is because Array indexing in Swift, and in many different languages, starts at 0. So if you want to access the second value you would have to use numbers[1] and etc.

I hope that I managed to help you out here and I hope it now makes more sense to you.

If you need any more help then don't hesitate to ask.

-Luke