If else
If 是一個判別邏輯的程式,可以讓程式在某些情況下執行。
Example:
bool no_idea;
if (no_idea) {
keep_learning();
} else {
make_design();
}
if else statement 也可以是更複雜的結構:
int days_before_vacation;
if (days_before_vacation > 5) {
printf("days_before_vacation is more than 5\n");
}
else if (days_before_vacation > 3) {
printf("days_before_vacation is between 4 and 5\n");
}
else if (days_before_vacation > 1) {
printf("days_before_vacation is between 2 and 3\n");
}
else {
printf("days_before_vacation is 1 or less\n");
}
Last updated