-
Notifications
You must be signed in to change notification settings - Fork 0
/
comandos-repetição
46 lines (43 loc) · 1.03 KB
/
comandos-repetição
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
#
# Este script mostra, com exemplos, como usar os comandos "for, while, until e case" \n
#
#
echo "Escolha um exemplo:"
echo "1. Exemplo usando o comando 'for'"
echo "2. Exemplo usando o comando 'while'"
echo "3. Exemplo usando o comando 'until'"
read -p "Digite o número do exemplo: " choice
case $choice in
1)
echo "Exemplo usando o comando 'for':"
var=0
for ((i=0; i<=2000; i++)); do
var=$((var+1))
done
echo "O valor final de var é: $var"
;;
2)
echo "Exemplo usando o comando 'while':"
var=0
i=0
while [ $i -le 2000 ]; do
var=$((var+1))
i=$((i+1))
done
echo "O valor final de var é: $var"
;;
3)
echo "Exemplo usando o comando 'until':"
var=0
i=0
until [ $i -gt 2000 ]; do
var=$((var+1))
i=$((i+1))
done
echo "O valor final de var é: $var"
;;
*)
echo "Opção inválida."
;;
esac