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:


for i in $(seq 1 10); do echo $i; done


for ($i=1; $i>=10; $i++) {
echo "$i ";


for ($i=1; $i<=10; $i++) {
print "$i ";


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 :)

Tags: , , , , , , , ,

Post simili:

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.

5 Responses to “For loop explained (Bash, PHP, Perl, Phyton)”
  1. imprenta
    14:43 on September 12th, 2011

    I’t funny but things are like this

  2. head lice symptoms
    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!

  4. erkal
    21:33 on April 12th, 2008

    and in perl you can also do;
    foreach (1..10) {print “$_ “}

  5. Christian
    14:46 on April 11th, 2008

    In perl you can also do:

    for $i (1..10) { print “$i ” }

Leave a comment