Skip to content

Commit

Permalink
Update 05-loops-conditions-existing.md (Azure#2102)
Browse files Browse the repository at this point in the history
* Update 05-loops-conditions-existing.md

Clarifying that we do indeed support for loops with index. An example may be good because in some languages like python the index comes before the item.

* Address feedback

* url path

* Update 05-loops-conditions-existing.md
  • Loading branch information
TSunny007 authored Apr 8, 2021
1 parent 08cebb4 commit aa6d309
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion docs/tutorial/05-loops-conditions-existing.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ resource foo 'my.provider/type@2021-03-01' = [for <ITERATOR_NAME> in <ARRAY> = {

`ITERATOR_NAME` is a new symbol that is only available inside the body of the resource declaration. It can be any name you would like and represents the current item in the array.

Let's remove our condition and replace it with a loop based on an input of container names:
Let's remove our condition and replace it with a loop based on an input of container names:

```bicep
param containerNames array = [
Expand All @@ -85,6 +85,13 @@ resource blob 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06
}]
```

There's also a [loop index variant](../spec/loops.md#use-the-loop-index) which gives us access to the current item's index in the array:
```
resource blob 'Microsoft.Storage/storageAccounts/blobServices/containers@2019-06-01' = [for (name, index) in containerNames: {
name: '${stg.name}/default/${name}-${index + 1}'
}]
```

This change also implicitly changes the type of the `resource` into an array of resources (will show up as `resources[]` on hover), rather than a single resource. In order to access one of the resources, I use array access syntax just like I do for any array in Bicep. Let's add an output that emits the id of each blob container.

```bicep
Expand Down

0 comments on commit aa6d309

Please sign in to comment.