Purchase Solution

How to eliminate a break statement from a for loop

Not what you're looking for?

Ask Custom Question

Using the following code as an example, explain how, in general, one can remove the break statement and replace it with "better" code:
int count; for (count = 1; count <= 10 ; ++count) { if (count == 5) break; // LINE 5 };
Suppose we replace the line labeled "LINE 5" with a continue statement. How would you replace the early termination code with "better" structured code?

Purchase this Solution

Solution Summary

This solution shows how to remove a break statement from a for loop in two different ways. It also provides a short justification for why we would want to do this.

Solution Preview

There are multiple ways to eliminate the "break" from this loop. The
purpose of the "break" statement here is to cause the loop to exit
when the condition "count == 5" is met. ...

Purchase this Solution


Free BrainMass Quizzes
Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

C# variables and classes

This quiz contains questions about C# classes and variables.

C++ Operators

This quiz tests a student's knowledge about C++ operators.