// This program goes into an infinite loop
// You need to figure out why

public class Infinite {

    public static void main (String [] args) {
	int n = 1, sum = 0;
	
	// the loop computes the sum of all odd numbers <= 20
	while (n <= 20) {
	    sum = sum + n;
	}

	System.out.println("sum = " + sum);
    }
}

This is an example from CSci 1211 course.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.