Tuesday, November 4, 2014

Learn JavaScript - Looping


in this lesson you will learn the following : 
  • for loop.
  • while loop.
  • do while loop.
Watch the video here :
The code inside the video :

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>LoopingPage</title>
    <script>
      
        function ForLoop() {
            for (var i = 10; i > 0; i = i - 2) {
                //my code
                document.writeln("<h1> i = " + i + "</h1> ");
                if (i == 5) {
                    break;
                   // continue;
                }
            }
        }
        function WhileLoop() {
            var i = 1;
            while (i <= 10) {
                document.writeln("<h1> i = " + i + "</h1> ");
                i++;
            }
        }
        function DoWhile() {
            var i = 11;
            do {
                document.writeln("<h1> i = " + i + "</h1> ");
                i++;
            } while (i <= 10);
        }
    </script>
</head>
    <body>
        <input type="button" value="while loop" onclick="ForLoop()" />
        <input type="button" value="while loop" onclick="WhileLoop()" />
        <input type="button" value="Do While" onclick="DoWhile()" />
    </body>
</html>

questions :
1- what is the different between while loop and do while loop ?
2- write a loop that print numbers from 20 to 40 but if the number apply devided on 5 print "Boom" instead the number :) ?

Best Regards
Eng/ Mohamed Adam
TalentDevs

Next
This is the most recent post.
Previous
Older Post

0 comments:

Post a Comment