Conditional Expressions
It basically allows program to decide.
"if": condition is written in first parenthesis after this expression. When condition is "true", first code after parenthesis or curly brace will work.
Example:
Int score1=49;
Int score2=50;
if(score1<50) print("Failed");
if(score2>=50){
print("Passed");
}
/*
Output:
Failed
Passed
*/
"else": first curly brace after this expression works when first condition before this expression is "false".
Example:
Int age=17;
if(age<18) print("Child");
else{
print("Adult");
}
//Output: Child
"else if": If first condition before this expression is "false" and condition in te first parenthesis after this expression is "true", first code after parenthesis or curly brace will work.
Example:
Truth student=true;
Truth working=true;
if(student&&!working) print("Status: Student");
else if(working&&!student) print("Status: Working");
else{
print("Status: Both student and working");
}
//Output: Status: Both student and working