Here is a computer language comparison, All languages implement the same algorithm than the following comic strip:
Basic
5 i = 0
10 i = i + 1
15 print "I will not throw paper airplanes in class"
20 if i <= 500 then goto 10
Basic
10 FOR I=1 TO 500
20 PRINT "I will not throw paper airplanes in class."
30 NEXT I
Excel
=REPT("I will not throw paper airplanes in class. ",500)
Batch File (DOS .bat)
@ECHO OFF
SET MESSAGE=I will not throw paper airplanes in class
FOR /L %%I IN (1,1,500) DO ECHO %MESSAGE%
C#
@ECHO OFF
SET MESSAGE=I will not throw paper airplanes in class
FOR /L %%I IN (1,1,500) DO ECHO %MESSAGE%
ASP
<%
dim i
for i=1 to 500
response.write("I will not throw paper airplanes in class")
next
%>
PHP
<%?php
for ($i = 1; $i<=500; $i++) {
echo "I will not throw paper airplanes in class.\n";
}
?>
Perl
#!/usr/bin/perl
for ($i = 0; $i < 500; $i++) {
print "I will not throw paper airplanes in class.\n";
}
Perl
foreach $i (1 .. 500) { print "I will not throw paper airplanes in class."; }
Perl
print "I will not throw paper airplanes in class." for 1..500
Perl
Like it could run on almost any platform without recompiling:
public class Repeat {
public static void main(String args[]) {
for (int i = 0; i < 500 i++)
System.out.println("I will not throw paper airplanes in class.");
}
}
ColdFusion
<cfloop from="1" to="500" index="i">
<cfoutput>I will not throw paper airplanes in class</cfoutput>
</cfloop>
JavaScript
<script language="JavaScript">
for(i=0;i<500;i++) {
document.write("I will not throw paper airplanes in class");
}
window.print();
</script>
Pascal
program airplanes;
var i : integer;
begin
for i:=1 to 500 do
writeln('I will not throw paper airplanes in class');
end.
Java
static void main() {
int i;
for(i = 0; i < 500; i++) {
System.out.println("I will not throw paper airplanes in class");
}
}
Lisp
In pure lisp, a tail-recursive function:
(defun airplanes (n)
(cond ((< n 1) nil)
(t (print "I will not throw paper airplanes in class")
(airplanes (- n 1)))))
(airplanes 500)
Lisp
With a repeat in the ergonomic loop macro:
(loop repeat 500 do (print "I will not throw paper airplanes in class"))
SQL
declare @i int
set @i=0
while (@i<=500) begin
print ' I will not throw paper airplanes in class '
set @i=@i+1
end
C
class Airplane
{
public Airplane()
{
}
public static void main(String args[])
{
for( int i = 0 ; i < 500 ; i++ )
System.out.println("I will not throw paper airplanes in class.");
}
}
VI
500oI will not throw paper airplanes in class.<ESC>
TCSH
repeat 500 echo "I will not throw paper airplanes in class."
Visual Basic
Private Sub Worksheet_Activate()
Dim i%
For i = 1 To 500
Me.Cells(i, 1).Value = "I will not throw paper airplanes in class."
Next
End Sub
Assembler x86
mov ah, 09
mov dx, 0111
mov cx, 01F4
int 21
loop 0108
mov ax, 4C01
int 21
db "I will not throw paper airplanes in class", 0d, 0a, 24
Postscript
%!
/msg (I will not throw paper airplanes in class.) def
/mm { 25.4 div 72 mul } def
/Helvetica findfont 8 scalefont setfont
newpath
0 5 mm moveto
1 1 125 {
gsave
2.296 mm mul
0 exch translate
5 mm 52 mm 210 mm { 0 moveto msg show } for
grestore
} for
showpage
Ultraedit
- I will not throw paper airplanes in class.
- Tools --> Record Macro: CTRL+C, RTRN, CTRL+V
- Tools --> Stop Recording
- Tools --> Play Multiple Times (CTRL+L) : 498
Fortran 90
program airplanes
implicit none
integer :: i
do i=1,500
write(*,*) "I will not throw paper airplanes in class"
end do
end program airplanes
ALGOL
BEGIN
INTEGER i;
FILE F (KIND=REMOTE);
EBCDIC ARRAY E [0:41];
REPLACE E BY "I will not throw paper airplanes in class";
FOR i:=1 STEP 1 UNTIL 500 DO
BEGIN
WHILE TRUE DO
BEGIN
WRITE (F, *, E);
END;
END;
END.
Clipper (DBASE)
FOR i := 1 TO 500
? "I will not throw paper airplanes in class"
NEXT
WSH
Set WshShell=WScript.CreateObject("Wscript.Shell")
WshShell.Run "notepad"
WScript.sleep 500
For i=0 To 499
WshShell.SendKeys "I will not throw paper airplanes in class"
WScript.sleep 20
WshShell.SendKeys "{Enter}"
WScript.sleep 20
Next
WScript.sleep 3000
WshShell.SendKeys "%{F4}"
WScript.sleep 100
WshShell.SendKeys "N"
WScript.sleep 100
Set WshShell = Nothing
COBOL
PERFORM VARYING II FROM 1 BY 1 UNTIL II > 500
DISPLAY "I will not throw paper airplanes in class"
END-PERFORM
notepad
I will not throw paper airplanes in class.
CTRL+A, CTRL+C,
CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V
CTRL+A, CTRL+C,
CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V,
CTRL+A, CTRL+C,
CTRL+V, CTRL+V, CTRL+V, CTRL+V, CTRL+V
C++
Using template programming:
#include <iostream>
template<int i>;
struct loop{
static void body(){
loop<i-1>::body();
loop<0>::body();
}
};
struct loop<0>{
static void body(){
std::cout << "I will not throw paper airplanes in class\n";
}
};
int main()
{
loop<500>::body();
return 0;
}
Clean
Start :: {#Char}
Start = abort (fun 1)
where
fun :: Int -> {#Char}
fun n
| n <= 500 = "I will not throw paper airplanes in class.\n" +++ fun (n+1)
= ""
ADA95
with Ada.Text_IO;
use Ada.Text_IO;
procedure Fun is
begin
for I in 1..500 loop
Put_Line("I will not throw paper airplanes in class.");
end loop;
end Fun;
C++
Using meta programming
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
int main()
{
vector<string> messages(500, "I will not throw paper airplanes in class.");
copy(messages.begin(), messages.end(), ostream_iterator<string>(cout, "\n"));
return 0;
}
Emacs Lisp
(defun reflection ()
(let ((i 0))
(while (< i 500)
(princ "I will not throw paper airplanes in class.\n")
(setq i (1+ i)))))
(reflection)
Scheme
For the Guile interpreter:
#!/usr/bin/guile
!#
(define reflection
(lambda ()
(let ((i 0))
(while (< (i 500)
(display "I will not throw paper airplanes in class.\n")
(set! i (1+ i))))))
(reflection)
tcl
for{set i 0}{$i < 500}{incr i} {
puts "I will not throw paper airplanes in class\n"
}
smalltalk-80
500 timesRepeat:
[Transcript show:'I will not throw paper airplanes in class';cr]
Scheme
(letrec ((reflection
(lambda (msg n)
(if (> n 0)
(begin (display msg)
(reflection msg (- n 1)))))))
(reflection "I will not throw paper airplanes in class.\n" 500))
awk
$ awk 'BEGIN { for( i=0; i<500; i++ ) print "I will not throw paper airplanes in class" }'
C
Pre-ansi:
main(_)
{
_ <= 500 &&
printf("I will not throw paper airplanes in class\n", _ ) &&
main (_+1);
}
(n)ML
fun reverse(nil) = nil
| reverse(x::xs) = reverse(xs)@[x];
fun reverse(x) = if x=nil then nil else reverse(tl(x))@[hd(x)];
PROLOG
sorry :- sorry(500).
sorry(0).
sorry(N) :-
write('I will not throw paper airplanes in class'), nl,
N2 is N-1,
sorry(N2).
Haskell
sorry :: Int -> IO()
sorry count = if count >=0
then do putStrLn "I will not throw paper airplanes in class"
let count2 = count -1;
int do sorry count2
vi
For vi text editor:
iI will not throw paper airplanes in class[esc]yy499p
Forth
500 0 do ." I will not throw paper airplanes in class." cr loop
PHP
<?php echo str_repeat("I will not throw paper airplanes in class.<br />\n", 500); ?>
Batch (Microsoft .bat file)
@for /l %i in (1,1,500) do @echo I will not throw paper airplanes in class.
qBasic
for i=1 to 500
print "I will not throw paper airplanes in class."
next i
Python
Standard statement:
for i in range(1,500):
print "I will not throw paper airplanes in class"
Python
One-liner:
print "I will not throw paper airplanes in class\n" * 500
Ruby
500.times {
puts "I will not throw paper airplanes in class\n"
}
SH script
for i in `seq 500`;
do echo "I will not throw paper airplanes in class";
done
Makefile
all:
@echo "I will not throw paper airplanes in class." 1>&2
@if test $$MAKELEVEL -lt 500; then make 1>/dev/null; fi
Microsoft Visual C++
#include <windows.h>
#include <processs.h>
void thread_proc( void *ptr )
{
MessageBox( 0, "I will not throw paper airplanes in class", "", MB_OK ) ;
}
int main( void )
{
int i ;
for ( i = 0 ; i < 500 ; i ++ )
_beginthread( thread_proc, 0, 0 ) ;
return 0 ;
}
S-plus
rep("I will not throw paper airplanes in class.", 500)
nasm
str db "I will not throw paper airplanes in class",0ah, 0ch, 0
les esi, str
mov ecx, 500
LABEL:
push esi
call printf
pop eax
loop LABEL
|
|