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

Console error message

So while entering this code into Xcode I get an error in the console that reads:

Playground execution failed: /var/folders/pf/44bj9s515yz8gfskt9kckxw00000gn/T/lldb/673/playground183.swift:8:18: error: cannot invoke '<' with an argument list of type
'(Int, @lvalue [String])'
while todo.count < todo {
      ~~~~~~~~~~~^~~~~~

Here is my code:

// For-in

import UIKit

var todo : [String] = ["Return calls", "Write blog", "Cook dinner", "Pickup laundry", "Buy bulbs"]

var index = 0
while todo.count < todo {
    println(todo[INDEX])
    index++
}

1 Answer

I found my syntax error. The while loop should look like this:

while index < todo.count {
    println(todo[index])
    index++
}