In JavaScript, the jump command doesn't exist as a standalone command like it might in some other programming languages. However, you can achieve the functionality of "jumping" to another part of your code using control flow statements like Break and Continue.
The break statement ‘jumps out’ of a loop.
// break
for (initialization; condition; increment/decrement) {
// code block
if (condition_to_exit_loop) {
break;
}
// if condition is false
}
// break
for (let i = 0; i < 5; i++) {
if (i === 3) {
console.log("Loop interrupted at i = 3");
break;
}
console.log("i:", i);
}
The break statement ‘jumps out’ of a loop.
// continue
for (initialization; condition; increment/decrement) {
// code block
if (condition_to_skip_iteration) {
continue;
}
// if condition is false
}
// continue
for (let i = 0; i < 5; i++) {
if (i === 2) {
console.log("Skipping iteration at i = 2");
continue;
}
console.log("i:", i);
}