very frequently when you write code you desire to


Very frequently when you write code, you desire to perform distinct actions for different decisions. You can employ conditional statements in your code to do this.

In JavaScript we contain three conditional statements which are following:

  • if statement - employ this statement if you desire to execute a set of code when a condition is true
  • if...else statement - employ this statement if you desire to select one of two sets of code to execute
  • switch statement - employ this statement if you desire to choose one of many sets of code to execute

if( myVariable == 2 ) {

myVariable = 1;

} else {

myVariable = 0;

}

If the value of myVariable in code is 2 then the first condition appraise to true and the value of myVariable is set to 1. If it is anything apart 2 then the else part gets executed.

Now let us see an instance of a nested if statement in above code

if ( myVariable == 2 ) {

myVariable = 1;

} else {

If (myVariable == 5 ) {

myVariable = 3;

} else {

myVariable = 4;

}

}

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: very frequently when you write code you desire to
Reference No:- TGS0415974

Expected delivery within 24 Hours