Computer Science & C Programming


Go further: extending C syntax

  1. The if_goto can be simplified with a do_while statement:
int r=1, i=1; // combine declarations
do {
  r *= i; 
  i ++;
} while (i<=n);
return r;
  1. Or, more simply, with a while loop:
int r=1, i=1;
while (i<=n) {
  r *= i; 
  i ++;
} 
return r;

5 - 6