If Statement
The yadi statement is used to execute a block of code conditionally. You can include an anyatha block for the else condition.
Syntax
yadi(expression) anyatha Basic If Statement
A simple if statement without an else block:
purna age;
age = 25;
yadi(age >= 18) {
bhana("You are an adult.");
}If-Else Statement
An if statement with an else block:
purna age;
age = 15;
yadi(age >= 18) {
bhana("You are an adult.");
}anyatha {
bhana("You are a minor.");
}Nested If Statements
You can chain multiple if-else statements for more complex conditions:
purna score;
score = 85;
yadi(score >= 90) {
bhana("Grade: A");
}anyatha yadi(score >= 80) {
bhana("Grade: B");
}anyatha yadi(score >= 70) {
bhana("Grade: C");
}anyatha yadi(score >= 60) {
bhana("Grade: D");
}anyatha {
bhana("Grade: F");
}Complex Conditions
You can use logical operators to create complex conditions:
purna age;
purna income;
age = 25;
income = 50000;
yadi(age >= 18 && income >= 30000) {
bhana("You are eligible for a loan.");
}anyatha {
bhana("You are not eligible for a loan.");
}Next Steps
Now that you understand if statements in Lipi, you can learn more about: