|
| 1 | +private import AstNodes |
| 2 | +private import Expr |
| 3 | +private import Idents |
| 4 | +private import Stmts |
| 5 | +private import internal.Loops |
| 6 | +private import internal.ForStatement |
| 7 | + |
| 8 | +class Loops extends Stmts instanceof LoopsImpl { |
| 9 | + /** |
| 10 | + * Gets the condition expression of the loop. |
| 11 | + * |
| 12 | + * This is the expression that determines whether the loop continues executing. |
| 13 | + * For while and for loops, this is the explicit condition expression. |
| 14 | + * For do-while loops, this is the condition evaluated after each iteration. |
| 15 | + * For foreach loops, this represents an implicit condition checking if there are more elements. |
| 16 | + */ |
| 17 | + abstract Expr getCondition(); |
| 18 | + |
| 19 | + /** |
| 20 | + * Gets the body of the loop. |
| 21 | + * |
| 22 | + * The body contains the statements that are executed in each iteration of the loop. |
| 23 | + * In the CFG, control typically flows back from the end of the body to the loop condition |
| 24 | + * or to the update expression (in for loops). |
| 25 | + */ |
| 26 | + abstract Stmts getBody(); |
| 27 | + |
| 28 | + /** |
| 29 | + * Gets the initializer of the loop, if any. |
| 30 | + * |
| 31 | + * For for loops, this includes the variables initialized before the loop starts. |
| 32 | + * For foreach loops, this includes the key and value variables declared for iteration. |
| 33 | + * Other loop types may not have initializers. |
| 34 | + */ |
| 35 | + abstract Idents getInitializer(); |
| 36 | +} |
1 | 37 |
|
2 | 38 | /** |
3 | | - * Loop statements are not supported in `bicep` code. |
| 39 | + * A for statement in Bicep. |
| 40 | + * |
| 41 | + * In Bicep, for loops are used to iterate over arrays, integer ranges, or object properties. |
| 42 | + * They can be used to create multiple instances of resources, modules, variables, or properties. |
| 43 | + * |
| 44 | + * Example: |
| 45 | + * ```bicep |
| 46 | + * // Creating multiple storage accounts using a for loop with range |
| 47 | + * resource storageAcct 'Microsoft.Storage/storageAccounts@2023-05-01' = [for i in range(0, storageCount): { |
| 48 | + * name: '${i}storage${uniqueString(resourceGroup().id)}' |
| 49 | + * location: location |
| 50 | + * sku: { |
| 51 | + * name: 'Standard_LRS' |
| 52 | + * } |
| 53 | + * kind: 'Storage' |
| 54 | + * }] |
| 55 | + * ``` |
4 | 56 | */ |
| 57 | +class ForStatement extends Loops instanceof ForStatementImpl { |
| 58 | + /** Gets the condition expression of this for loop. */ |
| 59 | + override Expr getCondition() { |
| 60 | + result = ForStatementImpl.super.getCondition() |
| 61 | + } |
| 62 | + |
| 63 | + /** Gets the body of this for loop. */ |
| 64 | + override Stmts getBody() { |
| 65 | + result = ForStatementImpl.super.getBody() |
| 66 | + } |
| 67 | + |
| 68 | + /** Gets the initializer of this for loop. */ |
| 69 | + override Idents getInitializer() { |
| 70 | + result = ForStatementImpl.super.getInitializer() |
| 71 | + } |
| 72 | +} |
0 commit comments