if (<condition>) {
<code>
} else if (<condition>) {
<code>
} else {
<code>
}
/* example */
int money = 50;
if (money < 15) {
go_home();
} else if (money >= 600) {
buy_all();
} else {
buy_tickets(money / 15);
}
/* You can chain together as many else ifs as you want. But if there are
too many it will make the code hard to understand. In that case I would
recommend trying other solutions. */
if(raining == 0 || (windSpeed > 15 && temperature < 10))// ** missing if statement **
{
printf("Stay indoors.
");
}
else
{
printf("You can go outside.
");
}
return 0;
}
#include <stdio.h>
int main()
{
int n;
n = 10;
if(n >= 0) {
printf("The number is positive
");
}
else {
printf("The number is negative
");
}
return 0;
}
if ( TRUE ) {
/* Execute these statements if TRUE */
}
else {
/* Execute these statements if FALSE */
}
if ( TRUE ) {
/* Execute these statements if TRUE */
}
else {
/* Execute these statements if FALSE */
}
if ( condition to be checked) {
Statements-if-condition-true ;
}
else{
statements-if-condition-false ;
}
if (test expression) {
// run code if test expression is true
}
else {
// run code if test expression is false
}
// C program to illustrate nested-if statement
#include <stdio.h>
int main() {
int i = 20;
if (i == 10)
printf("i is 10");
else if (i == 15)
printf("i is 15");
else if (i == 20)
printf("i is 20");
else
printf("i is not present");
}
if (test expression)
{
// code
}