For loop explained (Bash, PHP, Perl, Phyton)

Ciao! E’ la prima volta che ti vedo qua, se vuoi seguirmi sottoscrivi il feed RSS.
If you’re new here, you may want to subscribe to my RSS feed. Thanks for visiting!

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

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.

2 Responses to “For loop explained (Bash, PHP, Perl, Phyton)”
  1. Christian
    14:46 on April 11th, 2008

    In perl you can also do:

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

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

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

Leave a comment

(required)

(required)



Comments links could be nofollow free.

Categories