Control program flow with if/else statements
Conditionals are control structures that allow your code to make decisions. They let you execute different code blocks based on whether a condition is true or false.
Executes code only if a condition is true.
`if (score >= 80) {
print('Pass');
}
`Provides an alternative code block.
`if (score >= 80) {
print('Pass');
} else {
print('Fail');
}
`Checks multiple conditions in order.
`if (score >= 90) {
print('A');
} else if (score >= 80) {
print('B');
} else if (score >= 70) {
print('C');
} else {
print('F');
}
`1. **Evaluate**: Check if the condition is true or false
2. **Branch**: Execute the matching code block
3. **Continue**: Skip other blocks and continue
When an if statement matches, the rest of the else-if and else blocks are skipped!