DEV Community

Cover image for While Loops
Mary Nyandia
Mary Nyandia

Posted on

While Loops

Basic While Loop
While loops run as long as a condition is true. This makes them flexible for tasks where the number of repetitions isn’t known in advance.

Break Statement
break lets you exit a loop early, even if the condition is still true. This is useful for stopping once a certain condition is met.

Continue Statement
continue skips the rest of the loop for the current iteration and moves to the next one. This is handy for filtering data during iteration.

Top comments (0)