From dab7263241d3a80a59a9ecd7acb2c9b011273208 Mon Sep 17 00:00:00 2001 From: Shivam Aggarwal Date: Mon, 3 Aug 2026 01:20:42 +0530 Subject: [PATCH] Fix: Corrected terminologies for break and continue. They shouldn't be called directive In JavaScript, break and continue are technically called statements, not directives or operators. Here is why they do not fit the other categories: ## Why they are Statements * They perform actions: A statement is a piece of code that instructs the computer to do something (like controlling the loop flow) rather than producing a value. * Official Spec: The ECMAScript (JavaScript) specification officially categorizes them as "Iteration Statements" or "Control Flow Statements." ## Why they are NOT Operators * Operators produce values: Operators (like +, ===, or &&) take operands, perform an action, and return a result. * break and continue return nothing: You cannot assign them to a variable (e.g., let x = break; is a syntax error). ## Why they are NOT Directives * Directives change environment behavior: In JavaScript, a directive is a literal expression that tells the browser engine to change how it parses code (for example, "use strict";). * They do not control loops: Directives apply to entire scripts or functions, not block-level loop iterations. --- 1-js/02-first-steps/13-while-for/article.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/1-js/02-first-steps/13-while-for/article.md b/1-js/02-first-steps/13-while-for/article.md index d1b749888f..3940487eb8 100644 --- a/1-js/02-first-steps/13-while-for/article.md +++ b/1-js/02-first-steps/13-while-for/article.md @@ -219,7 +219,7 @@ Please note that the two `for` semicolons `;` must be present. Otherwise, there Normally, a loop exits when its condition becomes falsy. -But we can force the exit at any time using the special `break` directive. +But we can force the exit at any time using the special `break` statement. For example, the loop below asks the user for a series of numbers, "breaking" when no number is entered: @@ -240,13 +240,13 @@ while (true) { alert( 'Sum: ' + sum ); ``` -The `break` directive is activated at the line `(*)` if the user enters an empty line or cancels the input. It stops the loop immediately, passing control to the first line after the loop. Namely, `alert`. +The `break` statement is activated at the line `(*)` if the user enters an empty line or cancels the input. It stops the loop immediately, passing control to the first line after the loop. Namely, `alert`. The combination "infinite loop + `break` as needed" is great for situations when a loop's condition must be checked not in the beginning or end of the loop, but in the middle or even in several places of its body. ## Continue to the next iteration [#continue] -The `continue` directive is a "lighter version" of `break`. It doesn't stop the whole loop. Instead, it stops the current iteration and forces the loop to start a new one (if the condition allows). +The `continue` statement is a "lighter version" of `break`. It doesn't stop the whole loop. Instead, it stops the current iteration and forces the loop to start a new one (if the condition allows). We can use it if we're done with the current iteration and would like to move on to the next one. @@ -262,9 +262,9 @@ for (let i = 0; i < 10; i++) { } ``` -For even values of `i`, the `continue` directive stops executing the body and passes control to the next iteration of `for` (with the next number). So the `alert` is only called for odd values. +For even values of `i`, the `continue` statement stops executing the body and passes control to the next iteration of `for` (with the next number). So the `alert` is only called for odd values. -````smart header="The `continue` directive helps decrease nesting" +````smart header="The `continue` statement helps decrease nesting" A loop that shows odd values could look like this: ```js run @@ -283,7 +283,7 @@ But as a side effect, this created one more level of nesting (the `alert` call i ```` ````warn header="No `break/continue` to the right side of '?'" -Please note that syntax constructs that are not expressions cannot be used with the ternary operator `?`. In particular, directives such as `break/continue` aren't allowed there. +Please note that syntax constructs that are not expressions cannot be used with the ternary operator `?`. In particular, statements such as `break/continue` aren't allowed there. For example, if we take this code: @@ -368,7 +368,7 @@ outer: for (let i = 0; i < 3; i++) { ... } ``` -The `continue` directive can also be used with a label. In this case, code execution jumps to the next iteration of the labeled loop. +The `continue` statement can also be used with a label. In this case, code execution jumps to the next iteration of the labeled loop. ````warn header="Labels do not allow to \"jump\" anywhere" Labels do not allow us to jump into an arbitrary place in the code. @@ -381,7 +381,7 @@ break label; // jump to the label below (doesn't work) label: for (...) ``` -A `break` directive must be inside a code block. Technically, any labelled code block will do, e.g.: +A `break` statement must be inside a code block. Technically, any labelled code block will do, e.g.: ```js label: { @@ -404,8 +404,8 @@ We covered 3 types of loops: - `do..while` -- The condition is checked after each iteration. - `for (;;)` -- The condition is checked before each iteration, additional settings available. -To make an "infinite" loop, usually the `while(true)` construct is used. Such a loop, just like any other, can be stopped with the `break` directive. +To make an "infinite" loop, usually the `while(true)` construct is used. Such a loop, just like any other, can be stopped with the `break` statement. -If we don't want to do anything in the current iteration and would like to forward to the next one, we can use the `continue` directive. +If we don't want to do anything in the current iteration and would like to forward to the next one, we can use the `continue` statement. `break/continue` support labels before the loop. A label is the only way for `break/continue` to escape a nested loop to go to an outer one.