Next-Gen App & Browser
Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles
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");
}
}
}
KaneAI - Testing Assistant
World’s first AI-Native E2E testing agent.