Examples of code from many different programming languages


C++
int main(int argc, char *argv[])
{
    for(int i = 0; i < 10; i++)
    {
         cout << "Hi\n";
     }
}

Java
class Foo
{
     public static void main(String args[])
     {
           for(int i = 0; i < 10; i++)
           {
                 System.out.println("Hi");
           }
     }
}

Old Basic
10 FOR $i = 1 to 10
20 print $i
30 NEXT $i


Perl
#!/usr/bin/perl
for $i (0 .. 9)
{
      print "Hi!\n";
}

Python
#!/usr/bin/python
for x in range(0,9):
   print x

Lisp
(define (count x y)
        (if (> x 0)
                (cons y (count (- x 1) y))
        )
)

(count 10 'hi)

Prolog
http://euclid.nmu.edu/~randy/Classes/CS322/Prolog/family_prolog

Questions:

1) Which code looks the easiest to understannd if you're not an expert?

2) Which code would you rather write if you're an expert?