/* 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 );
The loop runs forever.
count
is never changed.
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.
Is the code correct?