xref: /PHP-Parser/test/code/parser/stmt/loop/for.test (revision 9a5d5c11)
1For loop
2-----
3<?php
4
5// "classical" loop
6for ($i = 0; $i < $c; ++$i) {}
7
8// multiple expressions
9for ($a, $b; $c, $d; $e, $f) {}
10
11// infinite loop
12for (;;) {}
13
14// alternative syntax
15for (;;):
16endfor;
17-----
18array(
19    0: Stmt_For(
20        init: array(
21            0: Expr_Assign(
22                var: Expr_Variable(
23                    name: i
24                )
25                expr: Scalar_Int(
26                    value: 0
27                )
28            )
29        )
30        cond: array(
31            0: Expr_BinaryOp_Smaller(
32                left: Expr_Variable(
33                    name: i
34                )
35                right: Expr_Variable(
36                    name: c
37                )
38            )
39        )
40        loop: array(
41            0: Expr_PreInc(
42                var: Expr_Variable(
43                    name: i
44                )
45            )
46        )
47        stmts: array(
48        )
49        comments: array(
50            0: // "classical" loop
51        )
52    )
53    1: Stmt_For(
54        init: array(
55            0: Expr_Variable(
56                name: a
57            )
58            1: Expr_Variable(
59                name: b
60            )
61        )
62        cond: array(
63            0: Expr_Variable(
64                name: c
65            )
66            1: Expr_Variable(
67                name: d
68            )
69        )
70        loop: array(
71            0: Expr_Variable(
72                name: e
73            )
74            1: Expr_Variable(
75                name: f
76            )
77        )
78        stmts: array(
79        )
80        comments: array(
81            0: // multiple expressions
82        )
83    )
84    2: Stmt_For(
85        init: array(
86        )
87        cond: array(
88        )
89        loop: array(
90        )
91        stmts: array(
92        )
93        comments: array(
94            0: // infinite loop
95        )
96    )
97    3: Stmt_For(
98        init: array(
99        )
100        cond: array(
101        )
102        loop: array(
103        )
104        stmts: array(
105        )
106        comments: array(
107            0: // alternative syntax
108        )
109    )
110)
111