cloc3 Advocate
Joined: 13 Jan 2004 Posts: 4802 Location: http://www.gentoo-users.org/user/cloc3/
|
Posted: Tue Oct 08, 2024 2:26 am Post subject: ciclo assurdo di bash. |
|
|
ho scoperto un programmino elementare di bash che, secondo me, ha un comportamento balordo:
Code: |
#!/bin/bash
n=1;
max=94;
while [[ $n < $max ]]; do
echo $((n++));
done
n=1;
max=24;
while [[ $n < $max ]]; do
echo $((n++));
done
echo stop
|
in output ottengo:
Code: |
...
89
90
91
92
93
1
2
stop
|
in pratica, ci sono due cicli di while identici.
il primo è impostato per essere eseguito fino al ciclo 94 (escluso), ed effettivamente esce al ciclo 93.
il secondo è impostato per essere eseguito fino al ciclo 24, ma esce al ciclo 2.
dove sta il guaio? _________________ vu vu vu
gentù
mi piaci tu |
|