- ..clause 1..: Conditional judgment
- ..clause 2..: Sentence that judges condition
- ..clause 3..: Operator for comparison
Programs that had been made up to now were programs of all one-way traffic.
In a word, execute the sentence in the writing order from start to finish.
It was the simplest mechanism saying coming to ending if the sentence was lost.
If it is a really simple program, even this : though it manages to become.
It comes to a standstill at once when complex even a little processing is done.
Change the content of processing according to the condition to solve this problem.
There is money-> roast meat table d'hote and had - > bamboo basket Sova
The judgment on [noyouna] , condition is needed without fail.
In the world of computer, it is not ..the value of the numerical value.. ..another.. if it is said the condition.
In addition, only the comparison of two numerical values becomes a condition to put it concretely and it gets it.
If ([ifu]) sentence is prepared in C language as a sentence judged according to the condition.
The if sentence compares the values of two numerical values, and does the processing division based on the result.
The usage of the if sentence becomes as follows.
The comparison of numerical values by the if sentence is very lucid and simple.If (conditional expression) Sentence;
[ The truth ]
It means numerical values (Even the negative value :) other than 0 by how to call the conditional judgment.
The specified numerical value executes it, and in the if sentence, the numerical value executes and only) situation but 0 executes the sentence on side ..the truth it.. ..(...
[ Imitation ]
It means 0 by how to call the conditional judgment.
The execution result of this program becomes as follows.#include <stdio.h> int main(void) { int suuti = 10; if (suuti) printf("%d\n",suuti); return 0; }
In this program, int suuti=10;Though it makes
10
In this program, the value of suuti Though nothing is displayed when making it to 0
[ Initialization ]
Substitute the numerical value at the same time as declaring the variable.
The if sentence might be seen the sentence without the usage considerably only by reading the foregoing paragraph.
Anyway, only because whether 0 or not so can be judged.
However, if a usual calculation is combined with the if sentence, a more advanced comparison is possible.
For instance, when the number as which the value is the same is subtracted mutually, the answer : naturally It becomes 0.
If this character is used, the judgment of the value becomes possible by the subtraction.
Judge The following program uses the character, and the input number : 10.
This..program..execute..have..input..result..as follows..become.#include <stdio.h> int main(void) { int suuti; scanf("%d",&suuti); If (suuti - 10) Printf ("The input value : 10 \n"); return 0; }
It has ..the execution of this program.. and the result becomes as follows about .....
10 Input data
Though a very advanced comparison becomes possible, too, if this method is applied more complexly
135 Input data
The input value 10. Then, it is not.
Then, the operator only for the comparison is prepared in C language.
Use the == operator when you examine whether two numerical values are equal.
This operator calculates, that the result truly becomes it when two values are equal.
The value input by the == operator : the following program It is an example of examining it is ten.
[ = and == ]
Even the professional has what makes a mistake in = and == carelessly well.
= A right, left numerical value is a comparison equal. the substitution of ..peel.. [hidari] for the variable and ==
First of all, doubt here when it doesn't move as thought.
This..program..execute..have..input..result..as follows..become.#include <stdio.h> int main(void) { int suuti; scanf("%d",&suuti); If (suuti == 10) Printf ("The input value : 10 \ n"); return 0; }
The result when this program is executed and it inputs it excluding ten becomes as follows.
10 Input data
The input value,
The judgment is neatly done though the correspondence of the display and non-display ahead is opposite.
135 Input data