Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.
The if-else statement executes a block of statements if a condition is true. If the specified condition is false, it executes another block of statements. The if-else statement comes under JavaScript's conditional statements, which can be used to perform specified actions based on different conditions.
Syntax
if(condition){
//execute the statement if condition is true
}
else{
//execute the statement if condition is false
}
Code Example
The below Java program checks whether a number is even or odd.
public class EvenOdd {
public static void main(String[] args) {
int num=12;
if(num%2==0){
System.out.println("Even Number");
}
else{
System.out.println("Odd Number");
}
}
}
Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.
Start Free TestingEarn resume-worthy Selenium certifications that help you land a top job.
Learn MoreTest orchestration and execution cloud of 3000+ browsers and OS
24/7 support
Enterprise grade security
Fastest test execution cloud