DoLoop¶
The DO statement to repeatedly execute a set of statements.
声明¶
语法¶
DoLoop(do_loop_head head, stmt* body)
参数¶
head contains do loop header or loop control.
body contains do loop statements.
返回值¶
无。
描述¶
DoLoop statement nodes repeatedly executes a set of statements.
A labeled DO loop consists of the following:
- DOstatement
- Set of executable statements i.e., body of the - doloop
- Terminal statement, like - CONTINUEstatement
The DO variable must not be modified in any way within the range of the DO
loop.
Control must not jump into the range of a DO loop from outside its range.
After the terminal statement of a DO loop is executed, the following steps are
performned:
- The value of the - DOvariable, if any, is incremented.
- The iteration count of the loop statement is decremented by one. 
- The iteration count of condition is tested. 
类型¶
Accessible global identifier and a sequence of zero or more statements or
construst that make the DO range.
示例¶
program doloop
    implicit none
    integer :: i, j
    j = 0
    do i = 1, 10
        if (i == 2) cycle
        j = j + i
    end do
    if (j /= 53) error stop
    print *, j
end program
ASR:
(TranslationUnit
    (SymbolTable
        1
        {
            doloop_03:
                (Program
                    (SymbolTable
                        2
                        {
                            i:
                                (Variable
                                    2
                                    i
                                    Local
                                    ()
                                    ()
                                    Default
                                    (Integer 4 [])
                                    Source
                                    Public
                                    Required
                                    .false.
                                ),
                            j:
                                (Variable
                                    2
                                    j
                                    Local
                                    ()
                                    ()
                                    Default
                                    (Integer 4 [])
                                    Source
                                    Public
                                    Required
                                    .false.
                                )
                        })
                    doloop_03
                    []
                    [(=
                        (Var 2 j)
                        (IntegerConstant 0 (Integer 4 []))
                        ()
                    )
                    (DoLoop
                        ((Var 2 i)
                        (IntegerConstant 1 (Integer 4 []))
                        (IntegerConstant 10 (Integer 4 []))
                        ())
                        [(If
                            (IntegerCompare
                                (Var 2 i)
                                Eq
                                (IntegerConstant 2 (Integer 4 []))
                                (Logical 4 [])
                                ()
                            )
                            [(Cycle)]
                            []
                        )
                        (=
                            (Var 2 j)
                            (IntegerBinOp
                                (Var 2 j)
                                Add
                                (Var 2 i)
                                (Integer 4 [])
                                ()
                            )
                            ()
                        )]
                    )
                    (If
                        (IntegerCompare
                            (Var 2 j)
                            NotEq
                            (IntegerConstant 53 (Integer 4 []))
                            (Logical 4 [])
                            ()
                        )
                        [(ErrorStop
                            ()
                        )]
                        []
                    )
                    (Print
                        ()
                        [(Var 2 j)]
                        ()
                        ()
                    )]
                )
        })
    []
)