Skip to main content

This documentation is for an older version of this product. See the latest version of this content.Opens in a new tab

If 文

If 文を使用して条件を評価し、その条件を基に実行するコードを決定できます。単純なコマンドと異なり、は複数の引数、コマンド・キーワード、コード・ブロックを含みます。コード・ブロックとは、中括弧内にある複数のコード行のことです。コード・ブロック内や前に、改行が存在する場合もあります。If 文の構文は以下のとおりです。


if (condition_1) {code_1} elseif (condition_2) {code_2} ... elseif (condition_N-1) {code_N-1} else {code_N}

条件を括弧で囲むことができます。ただし、これは必須ではありません。ElseIfElse はオプションで、2 つ以上の ElseIf を指定できます。

Root クラス・メソッド内で If を使用した例は以下のとおりです。

VS Code - ObjectScript


Class ObjectScript.Examples
{

/// root for my favorite team
ClassMethod Root()
{
    read "Team: ", t
    if (t = "") { quit }  // stop execution if no team is specified
    if (t = "METS") {
        write !, "Go METS!" }
    else {
        write !, "Boo ", t, "!" }
}
}
ターミナルを使用したテスト


USER>do ##class(ObjectScript.Examples).Root()
Team: METS
Go METS!
USER>do ##class(ObjectScript.Examples).Root()
Team: BLUE SOX
Boo BLUE SOX!
USER>do ##class(ObjectScript.Examples).Root()
Team:
USER>
FeedbackOpens in a new tab