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

how to stop infinite loop

when going through this lesson I got in an infinite loop, I can't even get back into xcode now. need help please.

Sidney Eubanks
Sidney Eubanks
3,864 Points

I think command z can get out out of it.

1 Answer

you have to add

index++

to your loop to increment your index or it can crash xcode. I would just make a new playground WITH that line in it and delete the old one.

var todo : [String] = [ "Return calls",
                        "Write post",
                        "Cook dinner",
                        "Pickup Laundry",
                        "Buy hyacinth bulbs" ]

var index = 0

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