HPlogo HP C/HP-UX Reference Manual: Version A.05.55.02 > Chapter 6 Statements

continue

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

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);
if (i == 2) /* leave out this test score */
continue;
tot_score += test_score;
} /* end for i */
fscanf(fp, "\n"); /* read end-of-line at end of */
/* each student's data */
average = tot_score/4.0;
printf("\nAverage test score: %4.1f\n", average);
} /* end while */
fclose(fp);
}

If you execute this program, you get the following output:

Student's name: Barry Quigley
Grades: 85 91 88 100 75
Average test score: 87.8

Student's name: Pepper Rosenberg
Grades: 91 76 88 92 88
Average test score: 86.8

Student's name: Sue Connell
Grades: 95 93 91 92 89
Average test score: 92.2

© Hewlett-Packard Development Company, L.P.