+ 3

How ' continue ' and ' Break ' work

They are wierd as for continue it's really tricky

11th Mar 2021, 9:49 PM
Kwabena Karikari Affum
Kwabena Karikari Affum - avatar
19 ответов
+ 3
The "break" stops the loop, "continue" misses one iteration. For example, you have infinite loop that checks if user writes a valid password: let password while(true){ if (password = "1234") { console.log("password is valid") break } } Yeap, that's weird but its how "break" works (i know you can use "while (password != "1234")" here but anyway How does "continue" works? Fr i dont know some useful usages but there is example: for (i = 0; i < 10; i++) { if (i % 2 == 1) { continue } console.log(i) } /* Outputs: 2 4 6 8 10 */ Why is it? Cuz if "i" is odd, the loop skips it(fr idk if it'll output "0". I think that it shouldn't but nvm)
11th Mar 2021, 10:08 PM
Nazeekk
Nazeekk - avatar
+ 2
The loop is the one in the bracket or the one in the curly braces???????
12th Mar 2021, 9:07 AM
Kwabena Karikari Affum
Kwabena Karikari Affum - avatar
+ 2
the loop is both the round and curly braces... round braces define initialization, condition, and iteration end steps, while curly braces define the code body to be run at each iteration... round braces are here for convenience, as you could put initialization just before your loop, conditional at first in your loop code body, and iteration end... at end of loop code body ;) however, if you do not provide anything in the round braces, you must at least write it with two semi colon in it (each part could be empty, but curly braces with three expression are mandatory).
12th Mar 2021, 9:13 AM
visph
visph - avatar
+ 2
for (var i=1; i<=10; ++i) { console.log('iteration #'+i); }
12th Mar 2021, 9:23 AM
visph
visph - avatar
+ 2
Let's say you have an array of 3 things and you want to use a loop to go through them. Each time you enter the body of the loop (curly braces) is called an iteration. If you don't have a "break", "continue" or "return" keyword, the loop will only end after going through all 3 items. Using "continue" exits the current iteration but doesn't stop the loop. So, it'll go to the next iteration if you're not at the last item already. Using "break" not only exits the iteration but it stops the loop as well. It continues with the rest of the function that's after the loop. Using "return" not only exits the iteration and the loop, it immediately returns out of the function to continue with the rest of the programme.
12th Mar 2021, 11:04 PM
CamelBeatsSnake
CamelBeatsSnake - avatar
+ 1
Can give me an example of iteration
12th Mar 2021, 9:18 AM
Kwabena Karikari Affum
Kwabena Karikari Affum - avatar
+ 1
iteration is once execution of the loop code body (curly braces)
12th Mar 2021, 9:19 AM
visph
visph - avatar
+ 1
for (i = 0; i < 10; i++) { console.log("This is " + i + " iteration") }
12th Mar 2021, 9:21 AM
Nazeekk
Nazeekk - avatar
+ 1
Continue is used to skip any iteration according to user . Break used to break the execution of programm. If you want to know more click on the given link. https://www.geeksforgeeks.org/difference-between-continue-and-break-statements-in-c/ Happy coding😉😉😉😊😊 and Iterations means =>repetition of a process or utterance.
13th Mar 2021, 2:47 AM
Anurag Kumar
Anurag Kumar - avatar
+ 1
Break = exit/stops the looping Continue = skips the process of looping one time and go on to the next iteration CMIIW
13th Mar 2021, 6:03 AM
Syahrel
Syahrel - avatar
+ 1
break stops the loop, continue spins immediately to the beginning of the loop
13th Mar 2021, 8:22 PM
Sebastian Ahlborn
Sebastian Ahlborn - avatar
0
break: exit loop continue: go to next iteration, skipping remaining code in the loop block at this point.
11th Mar 2021, 10:54 PM
visph
visph - avatar
0
An example
12th Mar 2021, 9:20 AM
Kwabena Karikari Affum
Kwabena Karikari Affum - avatar
0
Try this
12th Mar 2021, 9:21 AM
Nazeekk
Nazeekk - avatar
0
Anurag study that's in C++ I'm talking about Javascript
13th Mar 2021, 7:50 PM
Kwabena Karikari Affum
Kwabena Karikari Affum - avatar
0
Kwabena Karikari Affum both of them are same used 😃😃 Just with a little different syntax
13th Mar 2021, 7:53 PM
Nazeekk
Nazeekk - avatar
- 1
Continue means that if we declare print 1 to 5 and continue =4 means that it escapes at 4 and print 1235 and break=4 means that print 123 and stops
13th Mar 2021, 3:04 PM
BODDU AVINASH
BODDU AVINASH - avatar
- 3
continue is skip one loop only, break is skip the entire loop, exit
13th Mar 2021, 2:25 PM
Omar
Omar - avatar
- 4
Mgfj if h kg ĐT
13th Mar 2021, 11:55 AM
mazin a
mazin a - avatar