go to previous page   go to home page   go to next page
/* Compute the sum of the integers 0 through 9 */
int count=0, sum=0;
while ( count < 10 )
{
  sum = sum + count ;
  continue;
  count= count + 1;
}
printf("sum = %d\n", sum );

Answer:

The loop runs forever. count is never changed.


To Be Continued

Of course, the altered fragment is bad code. You would never deliberately write something like that. Now consider the following fragment:

/* Compute the sum of the integers 0 through 9 */
int count=0, sum=0;

while ( 1 )
{
  sum = sum + count ;
  . . .
  count= count + 1;
}
printf("sum = %d\n", sum );

The code has been altered. It does not look very nice, this time.


QUESTION 3:

Is the code correct?