// program to print the value of i
for (let i = 1; i <= 5; i++) {
// break condition
if (i == 3) {
break;
}
console.log(i);
}
// program to find the sum of positive numbers
// if the user enters a negative numbers, break ends the loop
// the negative number entered is not added to sum
let sum = 0, number;
while(true) {
// take input again if the number is positive
number = parseInt(prompt('Enter a number: '));
// break condition
if(number < 0) {
break;
}
// add all positive numbers
sum += number;
}
// display the sum
console.log(`The sum is ${sum}.`);
for (let i = 1; i <= 10; i++) {
console.log(i);
if (i == 5) {
break;
}
}