The
do-while loop
Example
- Solution in
Java:
Scanner input = new Scanner(System.in);
int sum = 0;
int x = -1;
do
{
System.out.print("Enter an integer (ends if it is 0): ");
x = input.nextInt();
if ( x != 0 )
sum = sum + x;
} while ( x != 0 );
System.out.print(sum);
|
|
DEMO:
demo/05-loops/03-do-while/ReadAndSum.java