Adscend

Click Here



Click Here

Monday

If Else Statement

If Else Statement

Syntax
if(condition)
{
     // execute this block if condition is true 
}
else{
     // execute this block if condition is false 
}
Conditional statements are used to perform different actions based on different conditions.
1. If…else statements  are also known as conditional statements. This simply means that they are able to take action or decision based on various conditions.
2. If…else statements is used to check whether specified condition is true or false.
If the condition is true then the code of block inside if will be executed. If the condition is false then the code of block inside else will be executed.
3. If…else statements allows the computer to make decisions based on the values of variables which can take the specified action based on the input that is given.
If the decision or condition is true then the code of block inside if will be executed. If the decision or condition is false then the code of block inside else will be executed.


Example: 1

<script type="text/javascript">
var num1=20;
var num2=30;
if (num1<num2)
  {
    alert("This line will be shown on browser");
   }
else
   {
    alert("This line will not be shown on browser");
    }
</script>



Example: 2

<script type="text/javascript">
var num1=20;
var num2=30;
if (num1>num2)
  {
    alert("This line will not be shown on browser");
   }
else
   {
    alert("This line will be shown on browser");
    }
</script>





No comments:

Post a Comment