Jump Statement in Javascript
function getResult() {
let result = 10;
if (result > 0) {
return result; // Return a positive value
}
return 0; // Return a default value (not reached in this example)
}
for (let i = 1; i <= 5; i++) {
if (i === 3) {
continue; // Skip the remaining code for i=3
}
console.log(i + " ");
if (i === 4) {
break; // Exit the loop when i=4
}
}
console.log(getResult() + " ");
// Javascript does not support goto statement
Output
1 2 4 10
Jump Statements in Programming
Jump statements in programming allow altering the normal flow of control within a program. These statements provide a way to transfer the execution to a different part of the code, facilitating conditional exits, loop control, function return, or unconditional jumps.
Table of Content
- What is a Jump Statement?
- Break Statement
- Continue Statement
- Return Statement
- Goto Statement
- Jump Statement in C
- Jump Statement in C++
- Jump Statement in Java
- Jump Statement in Python
- Jump Statement in C#
- Jump Statement in Javascript
Contact Us