Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
An if statement inside another if statement. Used when a decision depends on a prior condition being true first.
if (age >= 18) {
if (hasLicense) {
cout << "Can drive";
} else {
cout << "Get a license first";
}
} else {
cout << "Too young";
}// Same logic, flattened:
if (age >= 18 && hasLicense) {
cout << "Can drive";
}Avoid deep nesting (3+ levels). Use logical operators or early returns to flatten the logic. Deep nesting makes code harder to read and debug.