Use return value of that function and call continue based on it:

for (var i = 0; i < 5; i++) {
    if (theFunction(i)) {
        continue;
    }
}

function theFunction(x){
    if (x == 3) {
        return true;
    }

    return false;
}

Btw in your code you have if(i=3){, be aware that you need to use == or ===, single equals sign is for assignment.

Answer from Martin Adámek on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Statements › continue
continue - JavaScript - MDN Web Docs - Mozilla
The continue statement terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration. let text = ""; for (let i = 0; i < 10; i++) { if (i === 3) { continue; } text += i; } console.log(text); // Expected ...
People also ask

What is the difference between break and continue in JavaScript?
break terminates the entire loop and moves execution to the first statement after the loop. continue skips only the current iteration and proceeds to the next one. Use when you want to stop looping altogether and when you want to skip specific iterations.
🌐
savvy.co.il
savvy.co.il › blog › javascript complete guide › javascript continue statement: a complete guide
JavaScript continue Statement: A Complete Guide | Savvy
Can I use continue inside a forEach callback?
No. Using continue inside a forEach() callback throws a syntax error because can only be used inside a loop construct. To achieve the same skip behavior, use return inside the callback instead - it exits the current callback and moves to the next element.
🌐
savvy.co.il
savvy.co.il › blog › javascript complete guide › javascript continue statement: a complete guide
JavaScript continue Statement: A Complete Guide | Savvy
Why does continue cause an infinite loop in my while loop?
This usually happens when the counter increment is placed after the continue statement. In a while loop, jumps back to the condition check and skips everything below it, including the increment. Move the increment before the to fix this. In a for loop, this is not an issue because the update expression runs automatically.
🌐
savvy.co.il
savvy.co.il › blog › javascript complete guide › javascript continue statement: a complete guide
JavaScript continue Statement: A Complete Guide | Savvy
🌐
W3Schools
w3schools.com › js › js_break.asp
JavaScript Break
let text = ""; loop1: for (let j = 1; j < 5; j++) { loop2: for (let i = 1; i < 5; i++) { if (i === 3) { break loop2; } text += i; } } Try it Yourself » · break and continue are the only JavaScript statements that can "jump out of" a code block.
🌐
W3Schools
w3schools.com › Jsref › jsref_continue.asp
JavaScript continue Statement
❮ Previous JavaScript Statements Next ❯ · Loop through a block of code, but skip the value of 3: let text = ""; for (let i = 0; i < 5; i++) { if (i === 3) continue; text += i + "<br>"; } Try it Yourself » · let text = ""; let i = 0; while (i < 5) { i++; if (i === 3) continue; text += i + "<br>"; } Try it Yourself » ·
🌐
W3Schools
w3schools.com › js › js_continue.asp
JavaScript Continue
let text = ""; loop1: for (let j = 1; j < 5; j++) { loop2: for (let i = 1; i < 5; i++) { if (i === 3) { continue loop2; } text += i; } } Try it Yourself » · break and continue are the only JavaScript statements that can "jump out of" a code block. ❮ Previous Next ❯ ·
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-continue-statement
JavaScript Continue Statement - GeeksforGeeks
November 19, 2024 - The continue statement in JavaScript is used to break the iteration of the loop and follow with the next iteration. Example of continue to print only odd Numbers smaller than 10 ...
🌐
Programiz
programiz.com › javascript › continue-statement
JavaScript continue Statement
You must increase the value of num before the continue statement is executed. Otherwise, you will end up creating an infinite loop because num <= 10 will always be true. ... When the if block is not executed, your code to increase num will also be skipped. Thus, you must increase num again outside the if block to prevent an infinite loop. JavaScript continue With Nested Loop.
Find elsewhere
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Loops_and_iteration
Loops and iteration - JavaScript - MDN Web Docs - Mozilla
A statement labeled checkIandJ contains a statement labeled checkJ. If continue is encountered, the program terminates the current iteration of checkJ and begins the next iteration. Each time continue is encountered, checkJ reiterates until its condition returns false.
Top answer
1 of 2
2

Putting in an else block would make the code functionally equivalent, yes. As for whether it's better? Like others have said, the JS interpreter won't care - it'll handle it the same way regardless. The only important thing then is human readability.

If the internal for loop is long and complicated and contains lots of other stuff, then using continue may well be a better option, as it clearly states to the reader that it doesn't matter what else is in the loop, it'll go to the next iteration. using an if/else means the user has to confirm that there is no code further down that will execute after the if/else.

In another situation, using if/else might be better because using continue might end up in code duplication, or later maintenance might add a couple of lines to the end of the loop, thinking that every iteration will pass through it (always make your code as idiot-proof as possible if someone else may be modifying it later!).

Ultimately it comes down to opinion and coding standards (if it's part of a larger project then it should match what is elsewhere as much as possible). Do whatever makes the code most understandable to you. Ask someone else to have a look at the end product if you can, see if they have a different opinion to you - it's always easier to read your own code, having someone else look at it can highlight things that aren't quite as clear as you think they are!

2 of 2
0

How zerkms noticed, js interpreter will run this code similarly.

In my opinion, code with if..else statement becomes more readable, and also continue statement could be used, when there is nothing to do at this step of loop.

🌐
Savvy
savvy.co.il › blog › javascript complete guide › javascript continue statement: a complete guide
JavaScript continue Statement: A Complete Guide | Savvy
February 18, 2026 - The continue statement in JavaScript is used to skip the current iteration of a loop and proceed to the next iteration. It is particularly useful when you need to bypass certain conditions within a loop without terminating the loop entirely.
🌐
DEV Community
dev.to › satyam_gupta_0d1ff2152dcc › master-the-javascript-continue-statement-a-deep-dive-with-examples-use-cases-d0e
Master the JavaScript Continue Statement: A Deep Dive with Examples & Use Cases - DEV Community
September 18, 2025 - As shown earlier, in a while or do...while loop, ensure that any variable controlling the loop's condition is still updated before the continue statement is called. Otherwise, the skipped iteration never updates the counter, and the loop condition never changes, leading to an infinite loop. ... javascript let i = 0; while (i < 5) { if (i === 2) { continue; // i is NEVER incremented past 2!
🌐
Pi My Life Up
pimylifeup.com › home › using the continue statement in javascript
Using the continue Statement in JavaScript - Pi My Life Up
May 16, 2022 - For the second example, we will explore how JavaScript’s continue statement works when used within a for loop. It is essentially the same as a while loop, but we will explore it still. Within this example, we will write a simple for loop that will increment our “i” variable from 0 to 10. We utilize an if statement within the loop to check if the current number is even.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript continue
JavaScript continue
November 15, 2024 - Typically, you use the continue with an if statement like this: // inside a loop if(condition){ continue; }Code language: JavaScript (javascript) In this syntax, the if statement specifies a condition to execute the continue statement inside a loop.
🌐
Scaler
scaler.com › topics › javascript-continue-statement
What is Continue Statement in JavaScript? - Scaler Topics
December 19, 2022 - When the program encounters the JavaScript continue statement, the control of the program immediately moves to the loop statement where it continues with the next iteration if the condition in the loop still holds.
🌐
CodeSignal
codesignal.com › learn › courses › revisiting-javascript-basics › lessons › javascript-conditional-statements-break-and-continue
JavaScript Conditional Statements, Break, and Continue
By combining these loops with conditional statements and incorporating the useful break and continue instructions, we achieve more robust and efficient code. Let's dive in! ... In JavaScript, the if statement triggers actions in our code based on a specific condition.
🌐
TechOnTheNet
techonthenet.com › js › continue.php
JavaScript: Continue Statement
Let's look at an example that shows how to use a continue statement in JavaScript. You can also use the continue statement to restart a new iteration of the while loop. ... var counter = 0; while (counter < 5) { counter++; if (counter == 3) { continue; } console.log(counter + ' - Inside while loop on TechOnTheNet.com'); } console.log(counter + ' - Done while loop on TechOnTheNet.com');
🌐
CodeHS
codehs.com › tutorial › 13353
Tutorial: Break and Continue in JavaScript | CodeHS
Learn how to use the break and continue statements in your JavaScript programs.
🌐
TutorialsPoint
tutorialspoint.com › javascript › javascript_continue_statement.htm
JavaScript - Continue Statement
The JavaScript continue statement tells the interpreter to immediately start the next iteration of the loop and skip the remaining code block. When a continue statement is encountered, the program flow moves to the loop check expression immediately ...
🌐
Tutorial Gateway
tutorialgateway.org › javascript-continue-statement
JavaScript continue Statement
March 28, 2025 - We placed the If condition inside the for loop to test whether (i%2 != 0). If this condition is True, the continue statement will execute, and the iteration will stop at that number without printing the other lines of code.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › foreach-continue
Using Continue in JavaScript forEach() - Mastering JS
October 7, 2020 - [1, 2, 3, 4, 5].forEach(v => { if (v % 2 !== 0) { // SyntaxError: Illegal continue statement: no surrounding iteration statement continue; } });