Cut And Paste Code For Lesson 8


This week we learn how to break out of a loop early with the "break" command:

 

<!DOCTYPE html>
<html>
<body>
<p>Exit a loop using a "break."</p>
<script>
var i;
for (i = 0; i < 10; i++) {
document.write("The number is ");
document.write (i);
document.write ("<br>");

    if (i === 3) { break; }

}
</script>
</body>
</html>