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

im stuck

please help

while_loops.swift
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
while numbers 
Jhoan Arango
Jhoan Arango
14,575 Points

Let me work on your answer ! give me a few mins.. :)

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Jurgen:

β€œA while loop performs a set of statements until a condition becomes false” Excerpt From: Apple Inc. β€œThe Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l

let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] // the array of numbers

var index = 0 // A variable with a value of 0

while index < numbers.count { // This condition is true
    println(numbers[index]) // We print the values each time the loop passes by
    index++ // we add one value each time the loop passes until is about 10
}
/*
So while index is below 10, the loop will print out each number, and since
index is being added ONE value each time the loop passes, index will
become higher than 10 and it will make the condition false, and 
the loop dies. 
*/

hope you understand , if need any more clarification please let me know.

ok, thank you very much :D