# スクリプト制御ステートメント

Qlik Sense のスクリプトは多数のステートメントで構成されています。ステートメントは、正規のスクリプト ステートメントまたはスクリプト制御ステートメントのどちらかになります。

通常、制御ステートメントはスクリプト実行の流れを制御するために使用されます。制御ステートメントの各節は 1 スクリプト行に収める必要があり、セミコロンまたは改行コードで終了する必要があります。

プレフィックスは、制御ステートメントには適用されません。ただし、例外として、when および unless プレフィックスは、数個の特定の制御ステートメントで使用できます。

スクリプトのキーワードは、いずれも小文字と大文字の組み合わせが可能です。

各関数のドロップダウンを使用すると、その関数の簡単な説明や構文を確認できます。詳細を表示するには、構文の説明にある関数名をクリックします。

[](https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/script-control-statements.htm)

#### Call

call 制御ステートメントは、事前に sub ステートメントで定義されているサブルーチンを呼び出します。

[**Call**](https://help.qlik.com/ja-JP/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/Call.htm) name ( [ paramlist ])

[](https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/script-control-statements.htm)

#### Do..loop

do..loop 制御ステートメントはスクリプト反復構文で、論理条件が満たされるまで、1 つまたは複数のステートメントを実行します。

[**do**](https://help.qlik.com/ja-JP/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/do.htm) [ ( while | until ) condition ] [statements]  
[exit do [ ( when | unless ) condition ] [statements]  
loop [ ( while | until ) condition ]

[](https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/script-control-statements.htm)

#### Exit script

この制御ステートメントは、スクリプトの実行を停止します。スクリプト内の任意の場所に挿入できます。

[**exit script**](https://help.qlik.com/ja-JP/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/exit%20script.htm)[ (when | unless) condition ]

[](https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/script-control-statements.htm)

#### Exit error

Exit errorステートメントはスクリプトの実行を終了し、ユーザー定義のスクリプトエラーを発生させます。

[**exit error**](https://help.qlik.com/ja-JP/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/exit%20error.htm) expression [ (when | unless) condition ]

[](https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/script-control-statements.htm)

#### For each ..next

for each..next 制御ステートメントは、コンマ区切りリストの各値に対して、1 つまたは複数のステートメントを実行するスクリプト反復構文です。for と next で囲まれたループ内のステートメントは、リストの各値で指定された回数分実行されます。

[**For Each**](https://help.qlik.com/ja-JP/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/For%20Each.htm) var in list

[statements]

[exit for [ ( when | unless ) condition ]

[statements]

next [var]

[](https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/script-control-statements.htm)

#### For..next

for..next 制御ステートメントは、カウンタ付きのスクリプト反復構文です。for と next で囲まれたループ内のステートメントは、カウンタ変数の初期値と最終値で指定された回数分実行されます。

[**For**](https://help.qlik.com/ja-JP/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/For.htm)counter = expr1 to expr2 [ stepexpr3 ]

[statements]

[exit for [ ( when | unless ) condition ]

[statements]

Next [counter]

[](https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/script-control-statements.htm)

#### If..then

if..then 制御ステートメントは、1 つ以上の論理条件に応じて異なるパスに従うようスクリプトを強制実行させるスクリプト選択構文です。

情報メモif..then ステートメントは制御文であり、セミコロンまたは改行コードで終わっているため、使用可能な 4 つの節 (if..then、elseif..then、else、end if) が行をまたぐことはできません。

[**If**](https://help.qlik.com/ja-JP/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/If.htm) condition then

[ statements ]

{ elseif condition then

[ statements ] }

[ else

[ statements ] ]

end if

[](https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/script-control-statements.htm)

#### Sub

sub..end sub 制御ステートメントは、call ステートメントで呼び出されるサブルーチンを定義します。

[**Sub**](https://help.qlik.com/ja-JP/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/Sub.htm) name [ ( paramlist )] statements end sub

[](https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/script-control-statements.htm)

#### Switch

switch 制御ステートメントは、数式の値に基づいて異なるパスに従うようスクリプトを強制実行させるスクリプト選択構文です。

[**Switch**](https://help.qlik.com/ja-JP/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/ScriptControlStatements/Switch.htm) expression {case valuelist [ statements ]} [default statements] end switch