26. October 2009 21:03
I was browsing some of my last post and I saw I that I used a few “If” statements, but I didn’t mention anything on the “IF, ELSE” structure. This condition checking structure is used throughout most programming languages. And aside with looping is essential to a computer’s functioning. The scenario is that a condition will be checked in the “If” line of the statement. If that condition is true, then the code within it’s brackets will be executed. Otherwise nothing will happen. If there is and “Else” statement after the “If” statement, then that code will be executed if the “If” statement is false. There is also the “Else If” statement to further add conditions to be checked.
For example:
var x = 9;
if( x ==9)
{
document.write(x);
}
X is equal to nine, so the condition is true and the value of variable x will be printed on the screen.
var x = 9;
if( x ==5)
{
document.write(x);
}
else
{
document.write(“Not Five”);
}
In this case X is not equal to five, so the code in the “Else” statement is activated. Printing “Not Five” to the screen.
var x = 9;
if( x ==5)
{
document.write(x);
}
else if(x==9)
{
document.write(x);
}
else
{
document.write(“Not five or nine.”);
}
In this case the second condition checked is true, so 9 will be printed on screen. If both conditions were false, then the code of the “else” would have printed.
As I mentioned in the beginning of this post, these statements are essential for computer programming and are used greatly in loop structures to direct the program in what to do and when.
545ed2ff-e345-4663-8396-d84e94b6e668|0|.0