QUIZGUM

Coding Class

Quizgum : continue and break

continue statement and break statement

continue statement

A statement that executes the next statement instead of executing the statement that should be encountered when the continue statement is encountered.

Should we take a look?

The situation is outputting from 1 to 10 in the for statement, where 7 is not output and 8 is output because the continue statement is encountered in the order of 7 days. Use the ^-^ if statement.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>JavaScript</title>
<style type="text/css">
</style>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.0.min.js" ></script>
<script type="text/javascript">
    for(a = 1; a <= 10; a++){
        if(a == 7){
            continue;
        }
        document.write(a+"<br />");
    }
</script>
</head>
<body>
</body>
</html>

The result of the source above shows that if the output of 7 is used to execute the continue statement when a is 7, the output goes to 7 afterwards.

break statement

A break statement exits immediately when a break statement is encountered in an if, switch, for, or while statement.

In other words, if you program it to print from 1 to 7, but you execute break statement at 7, it will not be printed from 7.
The reason is that break breaks out of the condition or loop that was being executed.
In the example above, let's change continue to break to see the result.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>JavaScript</title>
<style type="text/css">
</style>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.0.min.js" ></script>
<script type="text/javascript">
    for(a = 1; a <= 10; a++){
        if(a == 7){
          break;
        }
        document.write(a+"<br />");
    }
</script>
</head>
<body>
</body>
</html>

If you look at the above result, you can see that it does not print from 7. Because I met the brake door on the turn to print 7.