(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...

Assume you have opened and connected stream variables fileIn and fileOut. Assume further that you have finished with input file, but want to read the input file a second time. What is necessary to set the stream state to reread the file from the start?

What will be an ideal response?

Computer Science & Information Technology

The __________ approach means that the operating system allocates the processor to a process and when the process blocks or is preempted, feeds it back into one of several priority queues.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

The server, which acts as the "cloud," is never physically seen by the user

Indicate whether the statement is true or false

Computer Science & Information Technology

Provide steps in verifying hashes.

As mentioned before, a common use for hashes is to verify file integrity. Follow the steps below to use SHA-2-256 hashes to verify the integrity of sample.img, a file downloaded from the Internet.

Computer Science & Information Technology