Dear nitin,
if ( TRUE ) Execute the next statement
if ( TRUE ) {
// Execute these statements if TRUE
}
else {
// Execute these statements if FALSE
}
if ( <condition> ) {
// Execute these statements if <condition> is TRUE
}
else if ( <another condition> ) {
// Execute these statements if <another condition> is TRUE and
// <condition> is FALSE
}
The switch statement provides a convenient alternative to the if when dealing with a multi-way branch. Suppose we have some integer value called test and want to do different operations depending on whether it has the value 1, 5 or any other value, then the switch statement could be employed:-
switch ( test ) {
case 1 :
// Process for test = 1
...
break;
case 5 :
// Process for test = 5
...
break;
default :
// Process for all other cases.
...
}
Please feel free to ask your queries here. We are all IITians and here to help you in your IIT JEE preparation.
All the best.
Win exciting gifts by answering the questions on Discussion Forum. So help discuss any query on askiitians forum and become an Elite Expert Leagueaskiitian.
Now you score 5+15 POINTS by uploading your Pic and Downloading the Askiitians Toolbar respectively : Click here to download the toolbar..
Askiitians Expert
Sagar Singh
B.Tech, IIT Delhi