Difference between revisions of "For"
Jump to navigation
Jump to search
(→Python) |
|||
(18 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | {{ | + | {{lc}} |
[[wikipedia:for]] | [[wikipedia:for]] | ||
− | === | + | === Examples === |
[[for i in]] `ls sa??`; do [[sar -f]] /var/log/[[sysstat]]/$i; done | [[for i in]] `ls sa??`; do [[sar -f]] /var/log/[[sysstat]]/$i; done | ||
+ | |||
+ | YOURVAR="value1 value2 value3" | ||
+ | for i in $YOURVAR; do # Should not be quoted | ||
+ | echo "$i" | ||
+ | done | ||
+ | |||
+ | |||
+ | for i in $(seq 5); do | ||
+ | echo $i | ||
+ | done | ||
=== [[Python]] === | === [[Python]] === | ||
for i in range(5): | for i in range(5): | ||
do_some_function() | do_some_function() | ||
+ | |||
+ | * [[Ansible]]: <code>[[with_items:]]</code> | ||
+ | |||
+ | === Powershell === | ||
+ | [[for]] ($num = 1 ; $num -le 10 ; $num++){ "I count $num"} | ||
+ | |||
+ | == Terraform == | ||
+ | * [[Terraform expression]]: <code>[[Terraform expression: for|for]]</code> | ||
+ | * [[Terraform]]: <code>[[for_each]]</code> | ||
+ | * [[Terraform]]: [[Splat expression]] | ||
+ | * [[Terraform: dynamic blocks]] | ||
== Related terms == | == Related terms == | ||
* [[Use loops in task (Ansible)]] | * [[Use loops in task (Ansible)]] | ||
* <code>[[while]]</code> | * <code>[[while]]</code> | ||
− | * <code>[[ | + | * <code>[[until ... do]]</code> |
* <code>[[parallel]]</code> | * <code>[[parallel]]</code> | ||
− | * [[ | + | * <code>[[until]]</code> |
− | * [[ | + | * [[Flow control]] |
+ | * [[endfor]] | ||
== See also == | == See also == | ||
− | * {{ | + | * {{for}} |
− | * {{ | + | * {{flow control}} |
− | |||
[[Category:Programming]] | [[Category:Programming]] |
Latest revision as of 18:16, 27 October 2024
Examples[edit]
for i in `ls sa??`; do sar -f /var/log/sysstat/$i; done
YOURVAR="value1 value2 value3" for i in $YOURVAR; do # Should not be quoted echo "$i" done
for i in $(seq 5); do echo $i done
Python[edit]
for i in range(5): do_some_function()
Powershell[edit]
for ($num = 1 ; $num -le 10 ; $num++){ "I count $num"}
Terraform[edit]
Related terms[edit]
See also[edit]
for, for_each (Terraform), until ... do, while ... do
- Flow control,
if, for, while, defer
Advertising: