Question: Executing a continue statement in C causes the program to jump to the end of the current loop iteration. The stated rule for translating a

Executing a continue statement in C causes the program to jump to the end of the current loop iteration. The stated rule for translating a for loop into a while loop needs some refinement when dealing with continue statements. For example, consider the following code:

/* Example of for loop containing a continue statement */ /* Sum even numbers between 0 and 9 */ long sum= 0;

A. What would we get if we naively applied our rule for translating the for loop into a while loop? What would be wrong with this code?

B. How could you replace the continue statement with a goto statement to ensure that the while loop correctly duplicates the behavior of the for loop?

/* Example of for loop containing a continue statement */ /* Sum even numbers between 0 and 9 */ long sum= 0; long i; for (i = 0; 1

Step by Step Solution

3.50 Rating (147 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Our stated rule for translating a for loop into a while loop is j... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Systems A Programmers Perspective Questions!