Take Another Break
Another way to avoid an infinite loop is to use a break
statement. The break
statement in a while
loop works just like a break
statement in a for
loop. In most cases, it is better to rely on the condition becoming false, but the break
statement is a nice option to have.
Get Learning to Program now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.