Jump statement cont.
example
while (1) while (cnt < n)
{ {
scanf("%lf",&x); scanf("%lf",&x);
/* exit loop if x is negative */ /* disregard small value */
if (x < 0.0) if (x > -0.01 && x < +0.01)
break; continue;
printf("%f\n",sqrt(x)); ++cnt;
} sum += x;
/* break jumps to here */ /* continue jumps to here */
}
the return statement
- syntax: return; /* or */ return expression;
- semantic: program control is immediately passed back to the calling environment; if an expression follows return, then the value of the expression is returned to the calling environment as well
the dreaded goto statement
- to be used with a labeled statement; usage need to be justified
- example: program to find next prime number on p.67 of text