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

Josh Schlabach
Josh Schlabach
1,771 Points

While loop & if statement

After I watched this video, I have been seeing that the if statement is basically a while loop. Is this true? What is the difference between them?

alex gwartney
alex gwartney
8,849 Points

No a if statement and a while loop are two different things, A if statement is there to check if a condition just happened and if it did it will run either wise it will do something else. So a example of this would be if a button is pressed it would check if the button was pressed once then it would execute something.
A while loop will continually check for something until that value becomes false. So for instance if i have a button press and i want the words hello to display on the screen as long as that button is being pressed the while loop will keep checking and printing hello until its released. Hope fully this clears things up a bit.