else if statement code example

Example 1: js if else

If - Else Statements
if (condition) {
// what to do if condition is met
} else {
// what to do if condition is not met
}

Example 2: html if else statement example

<div *ngIf="!show">
    <div>show is false</div>
</div>
<div *ngIf="show">
  <div>show is ture</div>
</div>

Example 3: IF else statement

var age=20;
if (age < 18) {
	console.log("underage");
} else {
	console.log("let em in!");
}

Example 4: IF else statement

var age=20;
if (age < 18) {
	console.log("underage");
} else {
	console.log("let em in!");
}

Example 5: JavaScript if else and else if

if (condition) {
  //  block of code to be executed if the condition is true
}
//-------------
if (hour < 18) {
  greeting = "Good day";
}
//-------------
if (condition) {
  //  block of code to be executed if the condition is true
} else {
  //  block of code to be executed if the condition is false
}
//-------------
if (hour < 18) {
  greeting = "Good day";
} else {
  greeting = "Good evening";
}
//-------------
if (time < 10) {
  greeting = "Good morning";
} else if (time < 20) {
  greeting = "Good day";
} else {
  greeting = "Good evening";
}

Example 6: if statement

if( name = 'george washington'):
	print("You have the same name as the first president of the United States")
    // python 
else:
	print("You do not have the same name as George Washington")

Tags:

Cpp Example