※スタイルシート未対応ブラウザではレイアウトを正確に再現できません。
  > | advanced by | contents  | that returns in <    
                   < [modosusu] > Color magazine monochrome light and shade   font predetermined, Gothic Ming-style type longhand   size Konaka large   standard  


  Divide in case of two.   

  1. ..clause 1..: Processing for imitation
  2. ..clause 2..: The usage is the same.
  3. ..clause 3..: Make it legibly.

[1] Processing for imitation

It explained the method of controlling the execution of specific processing according to the condition by using the if sentence in the preceding chapter.
However, this method has only the selection whether to execute processing.
Though the example named there is money-> roast meat table d'hote and had - > bamboo basket Sova was written at the beginning of the preceding chapter
The method of the preceding chapter is had [datta] that doesn't do - > anything by eating there is money->.

When you want to make the sentence executed when not agreeing to not only the agreement with the condition but also the condition
Else (Els) sentence can be used with the if sentence.
Use the else sentence as follows.

 If (conditional expression) Sentence executed for the truth;Sentence executed for else imitation;
When the condition is an imitation, the following sentence of the else sentence is executed.
Neither sentence executed for the truth nor sentences executed for the imitation can be executed.
Only one is executed either without fail according to the condition.

It returns to contents.


[2] The usage is the same.

Even when the else sentence is applied, the usage of the if sentence is quite the same.
However, the sentence executed for the imitation was only applied as an option.
The following program is an example of having rewritten the program made in the preceding chapter by the else sentence.

 
#include <stdio.h> 

int main(void)  
{
	int suuti;  
	scanf("%d",&suuti);  
	If (suuti == 10) Printf ("The input value is ten.  \n"); Else printf ("The input value is not ten.  \n");  return 0;
}
The result when this program is executed and ten is input becomes as follows.

10   Input data
The input value is ten.
The result when this program is executed and it inputs it excluding ten becomes as follows.

135   Input data
The input value is not ten.
If the result is seen, the second sentence is executed for the imitation as understood.
However, because the if-else sentence is written in one line in this program
One line sideways becomes long, and it is not easy to read.

It returns to contents.


[3] Make it legibly.

Divide into two or more lines to write the if-else sentence legibly, and add the indent.
Concretely, it becomes easy to expect that the following writing will be done.
 
#include <stdio.h> 

int main(void) 
{
	if (suuti == 10) printf(The 
		input value is ..".. ten. \n"); 
	else printf(The input value is 
		not ..".. ten. \n"); 
}
Moreover, write as follows when you use the complex sentence by the if-else sentence.
 
#include <stdio.h> 

int main(void)  
{
	Input..value.\n");   
	} else { 
		Printf ("The input value is not ten.  \n");
	}
}
When this writing is used, the relation between the if sentence and the else sentence is understood at one view.
Because it becomes easy to see very much, we will recommend this writing to be used usually.
Though there are excluding this a lot and a person who uses the following writing, too
The author doesn't like it so much because he or she uselessly feels like length.
 
#include <stdio.h> 

int main(void)  
{

	if (suuti == 10)  
	{
		Printf ("The input value is ten.  \n");   
	}
	else 
	{
		Printf ("The input value is not ten.  \n");
	}
}

It returns to contents.


< - It is advanced -> | in | head that returns  to returning  next |.