# Break & Continue

The break and continue keywords are two important keywords that facilitates both conditional testing and looping. break Keyword The break keyword enables us to totally "jump" out of a loop or conditional testing. That is, whenever a loop or conditional testing is executing and meets the break keyword, that signifies the end of that loop or conditional testing. You will use the break keyword whenever you are looping for example and on meeting a condition you are satisfied with, you decide to end the loop. You therefore use the keyword to end it.
``````<script>
var num = 25;

for (var i = 2; i < num; i++){
if (num % i == 0){
alert(i+" is the smallest number that can divide "+num);
break;
}
}
</script>``````
Above, we are looping from the number "2" to "24" with the aim of finding the smallest number that can divide "25". Once we find a number that can do just that, we end the loop with the break keyword. continue Keyword The continue keyword on the other hand allows us to "jump" out of a particular loop execution and "continue" with the next execution. It does not end the whole loop rather it ends a particular loop execution and goes to the next. For example, assuming a loop was suppose to execute 5 times, we can use the continue keyword to stop the execution of one of the loops so that the loop executes only 4 times instead of 5.
``````<script>
var num = 4;

for (var i = 1; i <= num; i++){
if (i == 3){
continue; //When i becomes 3, the loop will jump to the next execution
}
}
</script>``````
Above, we are looping from the number "1" to "4" but once we get to "3", we jump over its execution and move to the next execution which is "4". SUMMARY
1. The break and continue keywords are two very important keywords that helps us in conditional testing/decision making and looping.
2. The break keyword enables us to end a loop whenever a condition is met.
3. The continue keyword enables us to end a particular execution of a loop while it moves to the next execution.
Take a short quiz on Break & Continue.
Ask a question or tell us if Break & Continue is easy or not.
cent?