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 If Statement

Payton Dwight
Payton Dwight
5,751 Points

declaration of card in cards

//: Playground - noun: a place where people can play

import UIKit

let cards=1...13

for card in cards
{
    if card==11
    {
        println("Jack")
    }
    else if card==12
    {
        println("Queen")
    }
    else if card==13
    {
        println("King")
    }
    else
    {
        println("Other card")
    }
}

// do i not have to declare card as a variable? is card just assumed to be whatever progressive number in the constant cards? is cards an array

1 Answer

Hi Payton,

Yes, the local variable holding the value in each iteration of the range is self-declared by the contents of the range. The range is not an array but behaves very similarly. Documentation is here.

The range is "a collection of consecutive index values" - the documentation explains that, so essentially ourRange[i] == i so the value at the index is the index itself.

I hope that makes sense!

Steve.