For loop explained (Bash, PHP, Perl, Phyton)
Quante volte vi sara’ capitato di scrivere un ciclo “for” nel vostro linguaggio di programmazione preferito per automatizzare un processo o per renderlo piu’ semplice?
Ecco come si scrive un ciclo “for” in 4 linguaggi di programmazione molto famosi:
Bash:
for i in $(seq 1 10); do echo $i; done
PHP:
for ($i=1; $i>=10; $i++) {
echo "$i ";
}
Perl:
for ($i=1; $i<=10; $i++) {
print "$i ";
}
Phyton:
for i in range(1, 11):
print i,
Per tutti questi script il risultato sarà sempre:
1 2 3 4 5 6 7 8 9 10
Provare per credere :)
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.
14:43 on September 12th, 2011
I’t funny but things are like this
16:53 on September 6th, 2011
Great website. Plenty of useful info here. I?m sending it to a few friends ans additionally sharing in delicious. And certainly, thank you to your sweat!
13:42 on May 26th, 2008
perl so hard i love Php so easy to work!
21:33 on April 12th, 2008
and in perl you can also do;
foreach (1..10) {print “$_ “}
14:46 on April 11th, 2008
In perl you can also do:
for $i (1..10) { print “$i ” }