HP C A.06.05 Reference Manual

Statements
continue
Chapter 6 157
continue
Syntax
continue;
Description
The continue statement halts execution of its enclosing for, while, or do/while loop and
skips to the next iteration of the loop. In the while and do/while, this means the expression
is tested immediately, and in the for loop, the third expression (if present) is evaluated.
Example
/* Program name is "continue_example". This program
* reads a file of student names and test scores. It
* averages each student's grade. The for loop uses
* a continue statement so that the third test score
* is not included.
*/
#include <stdio.h>
int main(void)
{
int test_score, tot_score, i;
float average;
FILE *fp;
char fname[10], lname[15];
fp = fopen("grades_data", "r");
while (!feof(fp)) /* while not end of file */
{
tot_score = 0;
fscanf(fp, "%s %s", fname, lname);
printf("\nStudent's name: %s %s\nGrades: ", fname, lname);
for (i = 0; i < 5; i++)
{
fscanf(fp, "%d", &test_score);
printf("%d ", test_score);