(Removing the continue Statement) Describe in general how you’d remove any continue statement from a loop in a program and replace it with some structured equivalent. Use the tech- nique you developed here to remove the continue statement from the program of 4.12.

What will be an ideal response?

A loop can be rewritten without a continue statement by moving all the code that appears in the body of the loop after the continue statement to an if statement that tests for the opposite of the continue condition. Thus, the code that was originally after the continue statement executes only when the if statement’s conditional expression is true (i.e., the “continue” condition is false). When the “continue” condi tion is true, the body of the if does not execute and the program “continues” to the next iteration of the loop by not executing the remaining code in the loop’s body.

```
// Structured equivalent for continue statement.
#include
using namespace std;

int main()
{
for ( int count = 1; count <= 10; count++ ) // loop 10 times
{
if ( count != 5 ) // if count == 5, skip to next iteration
cout << count << " ";
} // end for

cout << "\nUsed if condition to skip printing 5" << endl;
} // end main
```

Computer Science & Information Technology

You might also like to view...

Which of the following filenames will be displayed using the flower? search string?

A) flower B) flowerpot C) flowered D) flowers

Computer Science & Information Technology

What is the major benefit of using the Active Directory-Based Activation model?

What will be an ideal response?

Computer Science & Information Technology