No, break is the correct solution.
Adding a boolean variable makes the code harder to read and adds a potential source of errors.
More Related Contents:
- How many times does a (for) loop iterate? [closed]
- Difference between pre-increment and post-increment in a loop?
- Can I use break to exit multiple nested ‘for’ loops?
- How do I break out of a loop in Scala?
- Using Pointers in a for loop
- What does it mean to pass in a vector into a `for` loop versus a reference to a vector?
- What is the pythonic way to detect the last element in a ‘for’ loop?
- Register multiple routes using range for loop slices/map
- How can I break an outer loop with PHP?
- How to make a reverse ordered for loop?
- Breaking out of a for loop in Java [closed]
- How can I use break or continue within for loop in Twig template?
- Batch script for loop won’t set variable
- Print a triangular pattern of asterisks
- Google Apps Script – Label Email Based On Email Body [Optimize Code]
- R: Break for loop
- How to loop through array in batch?
- What is the difference between pairs() and ipairs() in Lua?
- How can I do a mutable borrow in a for loop?
- Captured Closure (for Loop Variable) in Go
- Better to have ajax inside or outside for-loop or for-loop at the server side? Javascript [closed]
- Looping over a Date or POSIXct object results in a numeric iterator
- For loop example in MySQL
- How to use range-based for() loop with std::map?
- Python lambda doesn’t remember argument in for loop [duplicate]
- Express for loops in swift with dynamic range
- Which loop is faster, while or for?
- Two semicolons inside a for-loop parentheses
- Understanding for loops in Python
- push() a two-dimensional array