next up previous contents
Next: 2つ以上のfor nextを使った繰り返し Up: 繰り返し、二つ以上の条件式 Previous: Sample Program 5b   Contents

Sample Program 5cとd

次にもっとたくさんの条件を一度に課すときのその条件文の正確な意味を 調べましょう。まず以下のサンプルを実行してみて下さい。
\begin{code}
100 a=1
110 b=0
120 c=10
130 if a=1 and b=10 or c=1 and a=10 or a=1 then
140 print ''yes''
150 end if
\end{code}

次に以下のサンプルを実行してみましょう。違いは条件文の中の括弧です。
\begin{code}
100 a=1
110 b=0
120 c=10
130 if (a=1 and b=10 or c=1) and (a=10 or a=1) then
140 print ''yes''
150 end if
\end{code}
最初のサンプルの実行では、"yes"と表示されるのに、2つ目は表示されないとおもいます。 括弧によって条件を満たすか否かのくくりかたが変わる事に注意して下さい。



Takeyoshi Nagai 2017-01-23