Skip to content

Instantly share code, notes, and snippets.

@deepakshrma
Created January 20, 2020 15:07
Show Gist options
  • Save deepakshrma/8b460e0cd7fbe2d30c20d7af7b704997 to your computer and use it in GitHub Desktop.
Save deepakshrma/8b460e0cd7fbe2d30c20d7af7b704997 to your computer and use it in GitHub Desktop.
[conditionalBreak] Weird Part: How to break the LOOP in JavaScript
function conditionalBreak() {
let x = 0;
let z = 0;
while (true) {
console.log("Outer loops: " + x);
x += 1;
z = 1;
let breakOuterLoop = false;
while (true) {
console.log("Inner loops: " + z);
z += 1;
if (z === 10 && x === 10) {
breakOuterLoop = true;
break;
} else if (z === 10) {
break;
}
}
if (breakOuterLoop) break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment