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

What does the computer mean when it says "Your code took to long to run."?

This happened to me while I tried to complete the while loop challenge.

while_loops.swift
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var index = 0
  while index < numbers.count {
  println(numbers[index])
  }

2 Answers

Logan R
Logan R
22,989 Points

If your program takes too long to run, say 1 minute, the challenge checker will automatically time out.

This is happening in your case because you never increment your index and the program is stuck in an infinite loop. You can fix this problem by adding one to your index after you print out your number.

var index = 0
  while index < numbers.count {
  println(numbers[index])
  index = index + 1
  }
Rodrigo Chousal
Rodrigo Chousal
16,009 Points

You are forgetting to increase the value of index inside the while loop, it is repeating the while loop infinite times because index is always 0.