CL 程式或程序中的 DO 指令及 DO 群組

Do (DO) 指令可讓您一起處理一組指令。

群組定義為 DO 指令與對應的 End Do Group (ENDDO) 指令之間的所有指令。

群組的處理通常取決於相關指令的評估。 Do 群組最常與 IFELSEMONMSG 指令相關聯。 以下是 Do 群組的範例。

Do 群組範例

如果邏輯表示式 (&A=&B) 為 true ,則會處理 Do 群組。 如果表示式不是 true ,則會在 ENDDO 指令之後開始處理; 會跳過 Do 群組。

In the following procedure, if &A is not equal to &B, the system calls PROCB. 不會呼叫 PROCA ,也不會處理 Do 群組中的任何其他指令。

更複雜的 Do 群組範例

Do 群組可以在其他 Do 群組內形成巢狀,最多為 25 層巢狀。

下列範例中有三個巢狀層次。 請注意 ENDDO 指令如何完成每一個 Do 群組。

巢狀 Do 群組的範例

In this example, if &A in the first nest does not equal 5, PGMC is called. If &A equals 5, the statements in the second Do group are processed. If &AREA in the second Do group does not equal YES, procedure ACCTSPAY is called, because processing moves to the next command after the Do group.

CL 編譯器未指出 Do 群組的開始或結束。 如果 CL 編譯器注意到任何不平衡狀況,則很難偵測實際錯誤。