- ..clause 1..: The condition processes it in case of two or more cases.
- ..clause 2..: Writing that sees easily
In the method of the current learning, two chose and was able to do only [no] processing ..one.. ..choice.. [naishi].
However, it is how much the actual necessity of three high [era**] judgment.
For instance, assume the relation between the admission fee and the age of a certain zoo was as follows.
| Division | Age | Admission fee |
|---|---|---|
| Infant | Three years old or less | Free of charge |
| Child | 4-12 years old | 250 yen |
| Adult | 13 years old or more | 400 yen |
Even this program : on the face of things though is seems to the problem.#include <stdio.h> int main(void) { int age; Printf ("Age"); scanf("%d",&age); If (Age < = 3) Printf ("Infant: Free \n");If (Age > = 4 & age < = 12) Printf ("Child: 250 yen \ n");If (Age > = 13) Printf ("Adult: 400 yen \n"); return 0; }
Only have to continue the if-else sentence to lose this uselessness.
In a word, in using the if sentence as an executable statement of the else sentence
The content judged immediately before can be made the best use of, and uselessness is lost.
The program that these those who think correct becomes as follows.
The point of this program is a point to use the if sentence for the sentence executed by the else sentence.#include <stdio.h> int main(void) { int age; Printf ("Age"); scanf("%d",&age); Infant..free. } else { Child. } else { Printf ("Adult: 400 yen \n"); } } return 0; }
Though uselessness in processing was certainly lost in the program of the preceding clause
It was not able to be said that the program would see the compliment easily.
Moreover, to swerve to the right fast by the indent
It is expected to become harder to see when conditions increase more than three.
The method is only in the disregard of the indent to make it to the sentence that sees this easily.
The following program is an example of making easily to see in disregarding the indent.
In this program, the if sentence ties just behind the else sentence.#include <stdio.h> int main(void) { int age; Printf ("Age"); scanf("%d",&age); Infant..free. } else if (age <= 12) { Printf ("Child: 250 yen \n"); } else { Printf ("Adult: 400 yen \n"); } return 0; }
The place where this writing is good is not to become long sideways even if the condition how many increases.
Though it expands fast below in adding if to the else sentence
It becomes a program that sees comparatively easily because it never expands horizontally.
This is a special example of becoming legibly when the indent is disregarded.
One using the indent becomes legible in case of almost.