+ 3
How ' continue ' and ' Break ' work
They are wierd as for continue it's really tricky
21 Respostas
+ 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)
+ 2
The loop is the one in the bracket or the one in the curly braces???????
+ 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).
+ 2
for (var i=1; i<=10; ++i) {
console.log('iteration #'+i);
}
+ 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.
+ 1
Can give me an example of iteration
+ 1
iteration is once execution of the loop code body (curly braces)
+ 1
for (i = 0; i < 10; i++) {
console.log("This is " + i + " iteration")
}
+ 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.
+ 1
Break = exit/stops the looping
Continue = skips the process of looping one time and go on to the next iteration
CMIIW
+ 1
break stops the loop, continue spins immediately to the beginning of the loop
0
break: exit loop
continue: go to next iteration, skipping remaining code in the loop block at this point.
0
An example
0
Try this
0
Anurag study that's in C++ I'm talking about Javascript
0
Kwabena Karikari Affum both of them are same used 😃😃 Just with a little different syntax
- 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
- 3
continue is skip one loop only, break is skip the entire loop, exit
- 4
Mgfj if h kg ĐT