Your files never leave your device
Advertisement

While Loops

A while loop keeps running a block of code as long as its condition is true. Be careful not to create infinite loops!

Basic While Loop

You must ensure the condition eventually becomes false, usually by updating a variable inside the loop.

Try It Yourself

        

Do...While Loop

A do...while loop guarantees the code runs at least once, because the condition is checked after the loop runs.

Try It Yourself

        

Practice

Challenge 1: Write a while loop that doubles a number starting from 1 until it's greater than 100.

Related Guides

Sponsored Utility
While You're Here
Sponsored Recommendations
Advertisement