Sunday, 11 June 2017

15.05.2017.

Monday.

 

⟹Javascript conditions


➡if

➡if else

➡else if

➡loop

➡for loop

➡while loop

➡do while loop

➡switch


⟹Example for if, if else, else if condition.

  <script>

     var mysalary=20000;

     var yoursalary=20000;

      if (mysalary>yoursalary){

         window.alert("My salary is greater than your salary.");

      }

      else if (mysalary==yoursalary){

        window.alert("My salary is same your salary.");

      }

      else {

        window.alert("My salary is less than your salary.");

      }

      </script>


⟹Different Kinds of Loops

JavaScript supports different kinds of loops

➡for - loops through a block of code a number of times

➡for/in - loops through the properties of an object

➡while - loops through a block of code while a specified condition is true

➡do/while - also lops through a block of code while a specified condition is true

    ⟹The For Loop

    ➡The for loop is often the tool you will use when you want to create a loop.

    ➡The for loop has the following syntax


    for (statement 1; statement 2; statement 3) {
        code block to be executed
    }


    ➡Statement 1  is executed before the loop (the code block) starts.

    ➡Statement 2 defines the condition for running the loop (the code block).

    ➡ Statement 3 is executed each time after the loop (the code block) has been     executed.


    <script>

    var text = "";

    var i;

    for (i = 0; i < 5; i++) {

        text += "The number is " + i + "<br>";

    }

    document.getElementById("demo").innerHTML = text;

    </script>


    ⟹The While Loop

    ➡The while loop loops through a block of code as long as a specified condition is true.

    ➡Syntax


    while (condition) {
        code block to be executed
    }
     while (i < 10) {
        text += "The number is " + i;
        i++;
    }

    ⟹The Do/While Loop

    ➡The do/while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true.

    ➡Syntax

    do {
        code block to be executed }
    while (condition);
    do {
        text += "The number is " + i;
        i++;
    }
    while (i < 10)
    ;  
      

     ⟹Example for switch condition.

    <p id="demo"></p>

    <script>
    var day;
    switch (new Date().getDay()) {
    case 0:
        day="Sunday";
        break;

        case 1:
            day="Monday";
            break;

            case 2:
                day="Tuesday";
                break;

                case 3:
                    day="Wednesday";
                    break;


                    case 4:
                        day="Thursday";
                        break;


                        case 5:
                            day="Friday";
                            break;

                            case 6:
                                day="Saturday";
                                break;
    }
    document.getElementById("demo").innerHTML="Today is " + day;


    </script>



    ⟹Keyword                                 Description

    ➡break              Terminates a switch or a loop.

    ➡continue          Jumps out of a loop and starts at the top

    ➡ debugger        Stops the execution of Javascript , and the debugging
                            function

    ➡do...while         Executes a block of statements , and repeats the block , while a
                             condition is true.

    ➡for                    Marks a block of statement to be executed , as long as a
                             condition is true

    ➡function            Declares a function.

    ➡if...else              Marks a block of statements to be executed , depending on a
                             condition.

    ➡return              Exits a function.

    ➡switch              Marks a block of statements to be executed , depending on
                            different cases

    ➡var                  Declears a variable.




    ........................................................
























    No comments:

    Post a Comment

    Machine Learning Annotation Introduction

    Data annotation in Machine Learning is the process of annotating/ labeling data to categorize the dataset to identify by ML models. It can b...