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 [Link];
public static void main(String[] args) {
String dataString = [Link]( "Enter an int
value:\n(the program exits if the input is 0)"); int data =
[Link](dataString);
int sum = 0;
while (data != 0) {
sum += data;
dataString = [Link]( "Enter an int value:\n(the
program exits if the input is 0)");
[Link](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 [Link];
public static void main(String[] args) {
String dataString = [Link]( "Enter an int
value:\n(the program exits if the input is 0)"); int data =
[Link](dataString);
int sum = 0;
while ( ;data != 0; ) {
sum += data;
dataString = [Link]( "Enter an int value:\n(the
program exits if the input is 0)");
[Link](null, "The sum is " + sum);
}
}