Page 314 - Web Applications (803) Class 11
P. 314

Ð ÐNested if statement

              Ð ÐSwitch statement
              The if Statement

              The if statement is the simplest conditional statement. Here, a statement or a collection of statements within the if
              block is executed only if a certain condition or expression evaluates to true. If the condition evaluates to false, then the
              control of execution is passed to the next statement after the if block. The syntax of the if statement is given below:

                 if (condition) {
                   //  block of code to be executed when the condition is true
                 }
              Flow diagram:

                                                              Start







                                                                if      False
                                                            condition



                                                            True


                                                            Statements




                                                              Stop

              Example:

                 <!DOCTYPE HTML>
                 <HTML>
                 <HEAD>
                 <TITLE> if statement </TITLE>
                 </HEAD>
                 <BODY>
                 <SCRIPT>
                 var num = parseInt(prompt("Enter the number: "));

                 if(num > 0)
                 {
                 document.write("Entered Number is Positive");
                 }
                 </SCRIPT>
                 </BODY>
                 </HTML>




                312     Touchpad Web Applications-XI
   309   310   311   312   313   314   315   316   317   318   319