# for



#### 1ere syntaxe:

```bash
for variable in liste_valeurs
    do instruction(s)
done
```

#### 2eme syntaxe:

```bash
for ((e1;e2;e3))
    do instruction(s)
done
```



### Exemples:

Parcourir les arguments passés au script:

```bash
for i in "$@"
do
		echo "Hi $i"
done
```

Parcourrir une liste:

```bash
for i in {1..5}
do
		echo "Hi $i"
done

Hi 1
Hi 2
Hi 3
Hi 4
Hi 5
```

```bash
# bash 4.0+
for i in {0. .8. .2}			# debut. .fin. .increment
do
  echo "Hi $i"
done

Hi 0
Hi 2
Hi 4
Hi 6
Hi 8
```



```bash
for ((i=0 ; 10 - $i ; i++))
do 
    echo "Hi $i"
done
```

```bash
for (( c=1; c<=5; c++ ))
do  
		echo "Hi $c"
done
```



### Continue

```bash
for i in {1..5}
do
	[[ "$i" == '4' ]] && continue;
	echo "Hi $i"
done

Hi 1
Hi 2
Hi 3
Hi 5
```



### Break

```bash
for i in {1..5}
do
  [[ "$i" == '4' ]] && break;
  echo "Hi $i"
done

Hi 1
Hi 2
Hi 3
```

