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

what is a while loop?

i cant understand what is a while loop and how to use it

1 Answer

A while loop allows you to tell your program to run a certain piece of code repeatedly until a certain condition defined, is not true anymore.

while (someuserinput >= 0) { // As long as someuserinput is greater or equal to 0 the program will repeat/cycle through the code inserted in the curly braces.
        your code that needs to be executed as long as the condition is true
    }

Hope this helped