conditional statements Pascal if then else if then
- Slides: 31
条件文(conditional statements) 条件文はPascal等では以下の形で書かれる。 if 式 then 文 else 文 入口 if 式 then 文 (例) if x=0 then begin x: =1; y: =3 end else x: =2 if文も、thenパートの 文とelseパートの文 がsingle entry, single exitならsingle entry, single exitである。 真 x: =1 x=0 偽 x: =2 y : = 3 出口X
break文の使用例 while x>0 do begin if x=5 then break; x : = x-1 end break文によって、 if文の出口は2 つになったが、 while文全体は single entry, single exitである。 入口 真 x=5 x>0 偽 真 偽 x : = x-1 出口
continue文の使用例 while x>0 do begin if x 8 then begin x : = x-1; continue end; x : = x-5 end continue文によって、if文 の出口は2つになったが、 while文全体はsingle entry, single exitである。 入口 真 x 8 真 x : = x-1 x>0 偽 偽 x : = x-5 出口
解答例 if x > 0 then x : = x – 1 else if y > 0 then y : = y – 1 else y : = y + 1 真 x : = x-1 偽 x>0 真 y : = y-1 y>0 偽 y : = y+1
解答例 while x>0 do begin if x=3 then break; y : = y + 1; x : = x - 1 end 真 偽 y : = y+1 x : = x-1 x=3 x>0 真 偽
解答例 while x>0 do begin while y>0 do begin if x=3 then break; z : = z + 1; y : = y - 1 end; x : = x – 1 end 真 偽 x>0 偽 x=3 偽 真 y>0 真 z : = z+1 x : = x-1 y : = y-1
練習問題4 以下のプログラム断片の制御フローを図示せよ。 while x>0 do begin while y>0 do begin if x 3 then begin y : = y – 1; continue end z : = z + 1; y : = y - 1 end; x : = x – 1 end
解答例 while x>0 do begin while y>0 do begin if x 3 then begin y : = y – 1; continue end z : = z + 1; y : = y - 1 end; x : = x – 1 end 真 偽 偽 x 3 真 真 y>0 偽 z : = z+1 y : = y-1 x : = x-1 x>0 y : = y-1
解答例 x : = 10; sum : = 0; L: sum : = sum + x; x : = x – 1; if x > 0 then goto L x : = 10 sum : = sum + x x : = x – 1 x>0
解答例 y : = 3; case x of 1 : y : = 1; 2 : y : = x * 2; 3 : if z = 0 then y : = y * y else y : = y * y end y : = 3 1 y : = 1 x 3 2 真 y : = x*2 y : = y*y z=0 偽 y : = y*y*y
解答例 while x>0 do begin while y>0 do begin if x=3 then break; L: z : = z + 1; y : = y - 1 end; x : = x – 1; if x = 2 then goto L end 真 偽 x>0 偽 x=3 偽 真 y>0 真 z : = z+1 y : = y-1 x : = x-1 偽 x=2 真
- Pascal elseif
- Blood shadow stays on the street
- Pascal if else
- Are switch statements faster than if/else
- If then else pseudocode and flowchart
- Delphi if then else
- If then else vhdl
- If then else
- Pseudo code app
- Ibm cognos if then else statement examples
- Nested if pseudocode
- If then else scratch
- Conditional statment
- 2-2 conditional statements
- Conditional statements matlab
- Sequential conditional and iterative
- Biconditional statement in java
- Venn diagram conditional statement
- Unit 2 logic and proof homework 3 conditional statements
- Real past conditional
- Biconditional statement
- Geometry conditional statements
- Inverse of the conditional statement
- Symbol of conditional statement
- Conditional control
- Complete the proof
- Nested conditional statements
- Negate the hypothesis and conclusion
- Conditional 4
- Latin conditional sentences
- Unit 3 lesson 1 conditional statements
- If you are a guitar player then you are a musician inverse