elementsCollection.forEach(function(element){
if (!element.shouldBeProcessed)
return; // stop processing this iteration
// This part will be avoided if not neccessary
doSomeLengthyOperation();
});
let i = 0;
let n = 0;
while (i < 5) {
i++;
if (i === 3) {
continue;
}
n += i;
}
// program to print the value of i
for (let i = 1; i <= 5; i++) {
// condition to continue
if (i == 3) {
continue;
}
console.log(i);
}
for (var i = 0; i < 10; i++) {
if (i == 5) { continue; } // skips the rest of the cycle
document.write(i + ", "); // skips 5
}
// program to calculate positive numbers only
// if the user enters a negative number, that number is skipped from calculation
// negative number -> loop terminate
// non-numeric character -> skip iteration
let sum = 0;
let number = 0;
while (number >= 0) {
// add all positive numbers
sum += number;
// take input from the user
number = parseInt(prompt('Enter a number: '));
// continue condition
if (isNaN(number)) {
console.log('You entered a string.');
number = 0; // the value of number is made 0 again
continue;
}
}
// display the sum
console.log(`The sum is ${sum}.`);
for (let i = 1; i <= 10; i++) {
if (i == 3 || i == 7) {
continue;
}
console.log(i);
}