BasicsTutorial/Relational Operators and the IF statement

Last-modified: 2009-11-27 (金) 19:36:35

Relational Operators and the IF statement

関係演算子とイフ命令文

The IF statement is used to tell if something is true.
イフ命令文は、何かが真実(true)かどうか見分けるのに用いられる。
This is how it is written.
これは、それが書かれる方法である。

If statement
    Do Stuff
[Else
    Do other stuff]
Endif

This is called pseudo code, it shows the general rule or how you would do something without the actual code.
これは 疑似コードと呼ばれていると、それが一般的な規則またはあなたが実際のコードなしで何かするだろう方法に明らかにする。
The square brackets show that this part is optional (you don’t need to always use else).
角括弧は、この部分がオプションである(あなたは、常に他の使用に、必要でない)ことを示す。
Also, notice how I have indented code inside the IF statement, this way you can see what is inside the statement and what isn’t.
また、私がどのようにイフ命令文の中にコードをくぼませたかについて気がつきなさい、このように、あなたは何が命令文内部にあるか、そして、何がそうでないか見ることができる。(イデント)
Try and use it.
それを使うよう努めなさい。
Basically the if statement checks the value of the statement, and if it equals anything other than 0 then the code after is executed by the computer.
基本的に、イフ命令文は命令文の値をチェックする、そして、それが0以外の何かに等しいならば、コードはコンピュータで thenの後に実行される。
However if the statement is equal to 0 then the code after else is executed instead.
しかし、イフ命令文が 0と等しいならば、elseの後の他のコードはその代わりに実行される。
It can be written as.
それは、書かれることができる。

If statement then Do Stuff

This can be quick if you want to do only one thing when using the IF statement, but I will mostly use the other method in this tutorial.
イフ命令文を使うとき あなたが1つの事だけをしたいならば、これは速くありえる、しかし、私は大部分はこのチュートリアルにおける他の方法を使用する。
Here is an example of the IF statement.
イフ命令文の例は、ここにある。

Input "Write a number: ",value
If value
    Print "You didn't write 0"
Else
    Print "You wrote 0"
Endif
Wait key

But that’s no use, we want to tell much more than if someone wrote 0 or not.
もし無駄でなければ、我々は誰かが 0以外を書いたかどうかを、非常に話したい。
That’s when the relational operators come in to use.
それは、関係演算子が使われる時である。
Relational operators, again, process 2 numbers and return a 1 or 0.
関係演算子は、再び、二つの数字を処理して、1または0を返す。
They are =, >, <, >=, <= and <>.
それは、=、>、<、>=、<=と<>である。

= returns 1 when both numbers are equal
両方の数が等しいとき、=は1を返す

> returns 1 when the first number is larger than the second
最初の数が第2より大きいとき、>は1を返す

< returns 1 when the first number is smaller than the second
最初の数が第2より少ないとき、<は1を返す

>= returns 1 when the first number is larger or equal than the second
2番目に最初の数がより大きいか等しいとき、>=は1を返す

<= returns 1 when the first number is smaller or equal than the second
2番目に最初の数がより少ないか等しいとき、<=は1を返す

<> returns 1 when both numbers are different
両方の数が異なるとき、<>は1を返す

So combine this with IF.
それで、これを イフと結合しなさい。

`Get numbers
Input "Give me a number ",numOne
Input "Give me another number ",numTwo
`If numbers are equal
If numOne = numTwo
    Print "Both numbers are the same"
Else
    `Otherwise if numOne is bigger than numTwo
    If numOne > numTwo
        Print "One is bigger than two"
    Else
        Print "Two is bigger than one"
    Endif
Endif
Wait key

If numOne is equal to numTwo, then the = operator returns a 1 and the IF statement detects that, and the first code is executed.
もし、numOneがnumTwoと等しいならば、 =オペレーターは1を返す、 そして、イフ命令文はそれを検出する、そして、 最初のコードは実行される。
Otherwise the next code is executed and numOne is tested against numTwo with the > operator.
さもなければ、次のコードは実行される、そして、 >オペレーターは numOneとnumTwoに対してテストされる。
If numOne is bigger than numTwo > returns a 1 and the first code is executed, else the second code is.
numOneがnumTwoより大きいならば、 >は1を返す、そして、最初のコードは実行される(第2のelseコードがそうである)。

Now, get that?
現在、それを得る?
I know it may be quite confusing, if it is, go back and read it all again.
私は それが全く混乱させるかもしれないということを知っている、そうであるならば、戻って、全くもう一度それを読みなさい。
Now lets combine the IF statement with Boolean Operators and relational operators.
現在、イフ命令文をブール演算子と関係演算子と結合することを放す。

`Get numbers
Input "Give me a number ",numOne
Input "Give me another number ",numTwo
`Get a word
Input "Give a word ",word$
`If numbers are equal
If numOne = numTwo and word$ = "Chicken!"
   Print "Both numbers are the same and you got the word right!"
Endif
Wait key

Now if numOne is equal to numTwo, then it returns a 1, and if word$ is equal to “Chicken!”
今 numOneがnumTwoと等しい、それから、 それは 1を返す、そして、word$と「チキン!」が同等
(yes, you can use relational operators with strings as well and numbers) then it returns 1.
それから、それは1を返す(はい、あなたは文字列と数でも関係演算子を使用することができる)。
Then you have the AND operator testing whether numOne = numTwo equals 1 and word$ = “Chicken” equals 1, and if they do then it prints the words.
あなたは持つ、そして、 numOne = numTwoが1 と word$ =「臆病な」に等しいかどうか調べているオペレーターが1に等しい、そして、それがするならば、それは語をプリントする。

But in the end, it’s not best to think about these operators in technical terms, you should just think of them as an English sentence.
しかし、結局は、専門用語でこれらの 演算子(オペレーター)のことを考えることは最良でないと、あなたはちょっと英語の文としてそれらの思わなければならない。
Like this…
this…のように

If numOne = numTwo and word$ = "Chicken!"

Translated…

If numOne is the same as numTwo and word$ is “Chicken!” then do the stuff

You’ll just get confused if you think “hmm, AND operator means that its testing the <= and <> operators for being 1…..”
あなたは「うーん、そして、オペレーターはそれにそれが<1…であるための=と<>オペレーター..」をテストすることを定めると思うならば、あなたはちょうど混乱する
I just thought it’s best to know how they actually work.
私は、ちょうどそれが実際にどのように働くかわかっていることが最良であると思った。

Anyway, time to move on…
いずれにしろ、動かす時間

Summary of Commands

命令の概要

· IF and ELSE and ENDIF - They are used together to do something if a condition is true or not true.
IFと、ELSE、そして、ENDIF - 状態が真実であるか 真実でないならば、それが何かするために一緒に使われる。

· IF and THEN - Quick and easy form of IF if you are in a hurry.
IF、そして、THEN - あなたが急いでそうであるイフの迅速かつ容易な形。
Also useful for keeping code compact.
また、コードをコンパクトにしておくことに役立つ。

End of Section Tasks

セクション終わりの作業

l Make a program ask the user for their name, and have a few tests to see if they are called certain things (e.g. James or Kate), and then print different comments depending on their names.
プログラムをユーザーにそれの名前を求めさせて、それが特定のもの(例えばジェームズまたはケイト)と呼ばれているかどうか見るために2、3のテストを受けなさい、それから、それの名前に従い異なるコメントをプリントしなさい。
Take into account if their name isn’t recognised.
それの名前が認められないならば、考慮しなさい。
This would be a simple artificial intelligence program J.
これは、単純な人工知能プログラムである(。