TI-Basic 89 程式設計/條件函式
外觀
If, Control(F2):1 是一個命令,用於確定下一行程式碼是否執行。
:If condition
- 其中 condition 是一個表示式,解析結果為 true 或 false
- 如果 condition 為真,則執行下一行的程式碼。否則該程式碼將被跳過。
- 5→x
- If x=5
- Disp "True"
True
If...Then...EndIf, Control(F2):2:1 是一組命令,用於確定是否執行程式碼塊。
:If condition Then :code-block :EndIf
- 其中 condition 是一個表示式,解析結果為 true 或 false
- 如果 condition 為真,則執行 code-block 中的程式碼。否則該程式碼將被跳過
- 其中 code-block 包含一行或多行程式碼
- 5→x
- If x=5 Then
- 7→y
- Disp "Y is",y
- EndIf
Y is 7
If...Then...Else...EndIf, Control(F2):2:2 是一組命令,用於確定兩個程式碼塊中的哪一個被執行。
:If condition Then :code-block 1 :Else :code-block 2 :EndIf
- 其中 condition 是一個表示式,解析結果為 true 或 false
- 如果 condition 為真,則執行 code-block 1 中的程式碼。否則它將跳到 code-block 2
- 其中 code-block 1 和 code-block 2 各包含一行或多行程式碼
- 8→x
- If x=5 Then
- Disp "X is five"
- Else
- Disp "X is not five"
- EndIf
X is not five
ElseIf...Then, Control(F2):2:3 是一個命令,可以用它在 If...Then...EndIf 程式碼中新增兩個以上的程式碼塊。
:If condition 1 Then :code-block 1 :ElseIf condition 2 Then :code-block 2 :EndIf
- 其中 condition 1 和 condition 2 是解析結果為 true 或 false 的表示式
- 如果 condition n 為真,則執行相應的 code-block n 中的程式碼。否則它將跳到下一個 ElseIf...Then 語句,跳到 Else 和 EndIf 之間的 code-block,或者直接跳到 EndIf,具體取決於設定方式。
- 其中 code-block 1 和 code-block 2 各包含一行或多行程式碼
- 8→x
- If x=5 Then
- Disp "X is five"
- ElseIf x=8 Then
- Disp "X is eight"
- EndIf
X is eight
- 8→x
- If x=5 Then
- Disp "X is five"
- ElseIf x=8 Then
- Disp "X is eight"
- Else
- Disp "X is neither 5 nor 8"
- EndIf
X is eight