CSC 161 Grinnell College Fall, 2011
Imperative Problem Solving and Data Structures

counting-loop.c: A basic program about loops

As a basic program about loops, consider the following code that prints the numbers from one to ten, with each number on a new line. Commentary after the program explains each element of this program.

 * Program using a simple loop that prints the numbers from 1 to 10.
#include <stdio.h>

  int i;

  printf("Program to print the numbers from 1 to 10.\n");

  for (i = 1; i < 11; i++)
      printf("%d\n", i);

  return 0;

Commentary on the counting-loop.c program

A for loop is composed of an initializing statement, and a body of actions. The initializing statement has three components.

This document is available on the World Wide Web as

created 28 July 2011 by April O'Neill
last revised 29 July 2011 by April O'Neill
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at