206k views
1 vote
write a loop that reads positive integers from stands input and that terinated when it reads an interger that is not positive after the loop termpinates

1 Answer

7 votes

Loop takes only positive numbers and terminates once it encounters a negative numbers.

Answer and Explanation:

Using javascript:

Var positiveInt= window.prompt("insert positive integer");

While(positiveInt>=0){

Alert("a positive integer");

Var positiveInt= window.prompt("insert positive integer");

}

Or we use the do...while loop

Var positiveInt= window.prompt("insert positive integer");

do{

Var positiveInt= window.prompt("insert positive integer");

}

While (positiveInt>=0);

The above program in javascript checks to see if the input number is negative or positive using the while loop condition and keeps executing with each input until it gets a negative input

User Joshua Augustinus
by
6.9k points