Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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++
}