xxxxxxxxxx
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
}
xxxxxxxxxx
var a = prompt("value 1")
var b = prompt("value 2")
var c = prompt("value 3")
var d = prompt("value 4")
var e = prompt("value 5")
if (a >= b && a >= c && a >= d && a >= e) {
console.log(a + " this is greater value")
}
else if (b >= a && b >= c && b >= d && b >= e) {
console.log(b + " this is greater value")
}
else if (c >= a && c >= b && c >= d && c >= e) {
console.log(c + " this is greater value")
}
else if (d >= a && d >= b && d >= c && d >= e ) {
console.log(d + " this is greater value")
}
else if(e >= a && e >= b && e >= c && e >= d){
console.log(e + " this is greater value")
}
else{"enter the valid number"}
xxxxxxxxxx
int age = 30;
if(age >= 30 && age <= 80){
System.out.println("Old");
}else if(age < 30 && >= 1){
System.out.println("Young");
}else{
System.out.println("Not Supported");
}
xxxxxxxxxx
# python program to illustrate If else statement
#!/usr/bin/python
i = 20
if (i < 15):
print("i is smaller than 15")
print("i'm in if Block")
else:
print("i is greater than 15")
print("i'm in else Block")
print("i'm not in if and not in else Block")
xxxxxxxxxx
var age=20;
if (age < 18) {
console.log("underage");
} else {
console.log("let em in!");
}
xxxxxxxxxx
if (condition1) {
// Code to be executed if condition1 is true
} else if (condition2) {
// Code to be executed if condition1 is false and condition2 is true
} else {
// Code to be executed if neither condition1 nor condition2 is true
}
xxxxxxxxxx
//An if statement can be followed ba an optional else statement, which
//executes whe the Boolean expression is false
if(Boolean_expression) {
// Executes when the Boolean expression is true
}else {
// Executes when the Boolean expression is false
}
xxxxxxxxxx
>> number=23
>> guess = input('Enter a number : ')
>> if guess == number:
>> print('Congratulations! You guessed it.')
>> elif guess < number:
**( It is giving me 'Invalid Syntax')**
>> else:
**( It is also giving me 'Invalid syntax')**