Jun 22, 2024
Conditional Statements Role: Used to perform different actions based on different conditions.
if
, else
, switch
statements.if
Statementif(fruit.equals('mango')) { print('King of fruits'); }
else
Statementif
statement to execute a different code block if the if
condition is false.switch
Statementmango
, orange
, etc.switch(fruit) {
case 'mango':
print('King of fruits');
break;
case 'orange':
print('Citrus fruit');
break;
// default case
default:
print('Unknown fruit');
}
equals
method rather than ==
.
if (str1.equals(str2)) { /* do something */ }
equals
, substring
, charAt
, etc.String fruit =