/** * Name: Erica Eddy * Course: CSCI 241 - Computer Science I * Section: 001 or 002 * Assignment: 1 * * This example shows how a set of 'if' statements can be replaced with a * single 'while' statement that depends on the same condition. */ import java.util.Scanner; public class BasicWhile { public static void main (String [] args) { // int x = 0; // // the long, tedious set of 'if' statements // if (x < 3) // { // System.out.println("x = " + x); // x++; // } // if (x < 3) { // System.out.println("x = " + x); // x++; // } // if (x < 3) { // System.out.println("x = " + x); // x++; // } // if (x < 3) // { // System.out.println("x = " + x); // x++; // } // System.out.println("after ifs, x = " + x); // reset loop control variable to 0 int x = 0; while (x < 3) { System.out.println("x = " + x); x++; } System.out.println("after loop, x = " + x); } }