You are on page 1of 2

NAME: SUN SHINE B.

SAMORANOS 3BSAcT/B DATE: 03/13/18


ASSIGNMENT

WHILE LOOP - is a control flow statement that allows code to be executed repeatedly based
on a given Boolean condition. The while loop can be thought of as a repeating if statement.

import javax.swing.JOptionPane;
public static void main(String[] args) {
String dataString = JOptionPane.showInputDialog( "Enter an int
value:\n(the program exits if the input is 0)"); int data =
Integer.parseInt(dataString);
int sum = 0;
while (data != 0) {
sum += data;
dataString = JOptionPane.showInputDialog( "Enter an int value:\n(the
program exits if the input is 0)");
JOptionPane.showMessageDialog(null, "The sum is " + sum);
}
}
FOR-LOOP - a for-loop (or simply for loop) is a control flow statement for specifying
iteration, which allows code to be executed repeatedly.

import javax.swing.JOptionPane;
public static void main(String[] args) {
String dataString = JOptionPane.showInputDialog( "Enter an int
value:\n(the program exits if the input is 0)"); int data =
Integer.parseInt(dataString);
int sum = 0;
while ( ;data != 0; ) {
sum += data;
dataString = JOptionPane.showInputDialog( "Enter an int value:\n(the
program exits if the input is 0)");
JOptionPane.showMessageDialog(null, "The sum is " + sum);
}
}

You might also like