Difference between revisions of "Hello world"

From CodeCodex

m (revert spam)
Line 1: Line 1:
 
==Implementations==
 
==Implementations==
 
=== Ada ===
 
=== Ada ===
<highlightsyntax>
+
<pre>
 
with Ada.Text_IO;
 
with Ada.Text_IO;
  
Line 8: Line 8:
 
   Ada.Text_IO.Put_Line("Hello World!");
 
   Ada.Text_IO.Put_Line("Hello World!");
 
end Hello;
 
end Hello;
</highlightsyntax>
+
</pre>
  
 
=== Algol 68 ===
 
=== Algol 68 ===
<highlightsyntax>print(("Hello, World!", new line))
+
<pre>
</highlightsyntax>
+
print(("Hello, World!", new line))
 +
</pre>
  
 
=== ASP ===
 
=== ASP ===
<highlightsyntax>
+
<pre>
 
<% Response.Write("Hello World!") %>
 
<% Response.Write("Hello World!") %>
</highlightsyntax>
+
</pre>
  
 
=== x86 Assembler ===
 
=== x86 Assembler ===
  
 
==== Turbo Assembler, Windows ====
 
==== Turbo Assembler, Windows ====
<highlightsyntax>
+
<pre>
 
     .model tiny
 
     .model tiny
  
Line 38: Line 39:
 
     ret
 
     ret
 
     end start
 
     end start
</highlightsyntax>
+
</pre>
  
 
==== Netwide Assember, GNU/Linux ====
 
==== Netwide Assember, GNU/Linux ====
<highlightsyntax>
+
<pre>
 
section .text
 
section .text
 
global _start
 
global _start
Line 58: Line 59:
 
msg db "Hello, world!", 0xa
 
msg db "Hello, world!", 0xa
 
msglen equ $ - len
 
msglen equ $ - len
</highlightsyntax>
+
</pre>
  
 
=== BASIC ===
 
=== BASIC ===
<highlightsyntax>
+
<pre>
 
print "Hello World!"
 
print "Hello World!"
</highlightsyntax>
+
</pre>
  
 
=== C ===
 
=== C ===
<highlightsyntax>
+
<pre class="c">
 
#include <stdio.h>
 
#include <stdio.h>
  
Line 74: Line 75:
 
     return 0;
 
     return 0;
 
}
 
}
</highlightsyntax>
+
</pre>
  
 
=== C++ ===
 
=== C++ ===
<highlightsyntax>
+
<pre class="c++">
 
#include <iostream>
 
#include <iostream>
  
Line 85: Line 86:
 
     return 0;
 
     return 0;
 
}
 
}
</highlightsyntax>
+
</pre>
 
OR
 
OR
<highlightsyntax>
+
<pre class="c++">
 
#include <iostream>
 
#include <iostream>
 
using namespace std;
 
using namespace std;
Line 96: Line 97:
 
     return 0;
 
     return 0;
 
}
 
}
</highlightsyntax>
+
</pre>
  
 
=== C# ===
 
=== C# ===
<highlightsyntax>
+
<pre class="c#">
 
using System;
 
using System;
  
Line 109: Line 110:
 
         }
 
         }
 
}
 
}
</highlightsyntax>
+
</pre>
  
 
=== Common Lisp ===
 
=== Common Lisp ===
<highlightsyntax>(write-line "Hello, World!\n")</highlightsyntax>
+
<pre>
 +
(write-line "Hello, World!\n")
 +
</pre>
 
..or..
 
..or..
<highlightsyntax>
+
<pre>
 
(defun main ()
 
(defun main ()
 
   (write-line "Hello, World!")
 
   (write-line "Hello, World!")
 
   0)
 
   0)
</highlightsyntax>
+
</pre>
  
 
=== Fortran ===
 
=== Fortran ===
<highlightsyntax>
+
<pre>
 
PROGRAM HelloWorld
 
PROGRAM HelloWorld
 
WRITE(*,*)"Hello, World!"
 
WRITE(*,*)"Hello, World!"
 
END PROGRAM
 
END PROGRAM
</highlightsyntax>
+
</pre>
  
 
=== Go ===
 
=== Go ===
<highlightsyntax>
+
<pre>
 
package main
 
package main
 
import "fmt"
 
import "fmt"
Line 134: Line 137:
 
   fmt.Println("Hello, World!")
 
   fmt.Println("Hello, World!")
 
}
 
}
</highlightsyntax>
+
</pre>
  
 
=== Groovy ===
 
=== Groovy ===
<highlightsyntax>
+
<pre>
 
println("Hello World!");
 
println("Hello World!");
</highlightsyntax>
+
</pre>
 
or
 
or
<highlightsyntax>
+
<pre>
 
println "Hello World!"
 
println "Hello World!"
</highlightsyntax>
+
</pre>
  
 
=== Haskell ===
 
=== Haskell ===
<highlightsyntax language="haskell">main = putStrLn "Hello World!"</highlightsyntax>
+
<pre class="haskell">
 +
main = putStrLn "Hello World!"
 +
</pre>
  
 
=== Io ===
 
=== Io ===
<highlightsyntax>"Hello, world!" println
+
<pre>
</highlightsyntax>
+
"Hello, world!" println
 +
</pre>
  
 
=== Java ===
 
=== Java ===
<highlightsyntax>
+
<pre class="java">
 
class HelloWorld
 
class HelloWorld
 
{   
 
{   
Line 161: Line 167:
 
         }
 
         }
 
}
 
}
</highlightsyntax>
+
</pre>
  
 
Alternatively:
 
Alternatively:
<highlightsyntax>
+
<pre class="java">
 
class HelloWorld
 
class HelloWorld
 
{   
 
{   
Line 173: Line 179:
 
         }
 
         }
 
}
 
}
</highlightsyntax>
+
</pre>
  
 
=== Lua ===
 
=== Lua ===
<highlightsyntax>print "Hello, world!"
+
<pre>
</highlightsyntax>
+
print "Hello, world!"
 +
</pre>
  
 
=== OCaml ===
 
=== OCaml ===
<highlightsyntax>
+
<pre>
 
  # print_endline "Hello world!";;
 
  # print_endline "Hello world!";;
 
  Hello world!
 
  Hello world!
 
  - : unit = ()
 
  - : unit = ()
</highlightsyntax>
+
</pre>
  
 
=== Pascal ===
 
=== Pascal ===
<highlightsyntax>
+
<pre class="pascal">
 
program HelloWorld;
 
program HelloWorld;
  
Line 193: Line 200:
 
   writeln('Hello, world!');
 
   writeln('Hello, world!');
 
end.
 
end.
</highlightsyntax>
+
</pre>
  
 
=== Perl ===
 
=== Perl ===
<highlightsyntax>
+
<pre>
 
print "Hello World\n";
 
print "Hello World\n";
</highlightsyntax>
+
</pre>
  
 
==== As PL File ====
 
==== As PL File ====
<highlightsyntax>
+
<pre>
 
print "Hello World\n";
 
print "Hello World\n";
</highlightsyntax>
+
</pre>
  
 
==== As CGI File ====
 
==== As CGI File ====
<highlightsyntax>
+
<pre>
 
#!/usr/local/bin/perl
 
#!/usr/local/bin/perl
 
print "Content-type: text/html\n\n";
 
print "Content-type: text/html\n\n";
 
print "<H1>Hello World</H1>";
 
print "<H1>Hello World</H1>";
</highlightsyntax>
+
</pre>
  
 
=== PHP ===
 
=== PHP ===
  
<highlightsyntax>
+
<pre class="php">
 
<?php
 
<?php
 
echo "Hello, world!\n";
 
echo "Hello, world!\n";
 
?>
 
?>
</highlightsyntax>
+
</pre>
  
 
=== PostScript ===
 
=== PostScript ===
Line 224: Line 231:
 
The strict equivalent to the other languages (print a string to standard output) would be:
 
The strict equivalent to the other languages (print a string to standard output) would be:
  
<highlightsyntax>(Hello, World!) =
+
<pre>
</highlightsyntax>
+
(Hello, World!) =
 +
</pre>
  
 
However, this is not typical of how PostScript is normally used, to generate and print page images.
 
However, this is not typical of how PostScript is normally used, to generate and print page images.
Line 231: Line 239:
 
The following version prints a page with the "Hello, World!" message.
 
The following version prints a page with the "Hello, World!" message.
  
<highlightsyntax>/Helvetica findfont % use a standard font
+
<pre>
 +
/Helvetica findfont % use a standard font
 
72 scalefont setfont % make it nice and big
 
72 scalefont setfont % make it nice and big
 
100 100 moveto % someplace convenient on the page
 
100 100 moveto % someplace convenient on the page
 
(Hello, World!) show
 
(Hello, World!) show
 
showpage
 
showpage
</highlightsyntax>
+
</pre>
  
 
=== Progress 4GL/ABL ===
 
=== Progress 4GL/ABL ===
<highlightsyntax>
+
<pre>
 
display "Hello World!".
 
display "Hello World!".
</highlightsyntax>
+
</pre>
  
 
=== Python ===
 
=== Python ===
  
<highlightsyntax language="python">
+
<pre class="python">
 
print "Hello, World!"
 
print "Hello, World!"
</highlightsyntax>
+
</pre>
  
 
=== Rexx ===
 
=== Rexx ===
  
<highlightsyntax>
+
<pre>
 
/* */
 
/* */
 
say "Hello, World!"
 
say "Hello, World!"
</highlightsyntax>
+
</pre>
  
 
=== Ruby ===
 
=== Ruby ===
  
<highlightsyntax>
+
<pre class="ruby">
 
puts "Hello, World!"
 
puts "Hello, World!"
  
Line 265: Line 274:
  
 
# OR
 
# OR
print "Hello, World!"
+
print "Hello, World!\n"
</highlightsyntax>
+
</pre>
  
 
=== Scheme ===
 
=== Scheme ===
 
+
<pre>
(display "Hello, world!")
+
(display "Hello, world!")
 +
</pre>
  
 
=== Seed7 ===
 
=== Seed7 ===
  
<highlightsyntax>
+
<pre>
 
$ include "seed7_05.s7i";
 
$ include "seed7_05.s7i";
 
   
 
   
Line 281: Line 291:
 
     writeln("Hello, world!");
 
     writeln("Hello, world!");
 
   end func;
 
   end func;
</highlightsyntax>
+
</pre>
  
 
=== Tcl ===
 
=== Tcl ===
Line 289: Line 299:
 
=== Turing ===
 
=== Turing ===
  
<highlightsyntax>
+
<pre>
 
put "Hello, World!"
 
put "Hello, World!"
</highlightsyntax>
+
</pre>
  
 
=== Visual Basic ===
 
=== Visual Basic ===
<highlightsyntax>
+
<pre class="vb">
 
Console.WriteLine("Hello, World!")
 
Console.WriteLine("Hello, World!")
</highlightsyntax>
+
</pre>
  
 
=== Zsh ===
 
=== Zsh ===
Line 332: Line 342:
 
[[Category:Progress 4GL/ABL]]
 
[[Category:Progress 4GL/ABL]]
 
[[Category:PostScript]]
 
[[Category:PostScript]]
[[Category:VisualBasic]]
+
[[Category:Visual Basic]]
 
[[Category:Zsh]]
 
[[Category:Zsh]]

Revision as of 17:32, 1 December 2010

Implementations

Ada

with Ada.Text_IO;

procedure Hello is
begin
   Ada.Text_IO.Put_Line("Hello World!");
end Hello;

Algol 68

print(("Hello, World!", new line))

ASP

<% Response.Write("Hello World!") %>

x86 Assembler

Turbo Assembler, Windows

    .model tiny

    .data
message    db    'Hello, World!'
    
    .code
    org 100h

start:
    mov ah,9
    mov dx,offset message
    int 21h

    ret
    end start

Netwide Assember, GNU/Linux

section .text
global _start
_start:
	mov	edx, msglen
	mov	ecx, msg
	mov	ebx, 0x1
	mov	eax, 0x4
	int	0x80

	mov	ebx, 0x0
	mov	eax, 0x1
	int	0x80

section .data
	msg	db	"Hello, world!", 0xa
	msglen	equ	$ - len

BASIC

print "Hello World!"

C

#include <stdio.h>

int main(void)
{
    printf("Hello, World!\n");
    return 0;
}

C++

#include <iostream>

int main()
{
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

OR

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello, World!" << endl;
    return 0;
}

C#

using System;

public class HelloWorld
{
    public static void Main()
        {
            System.Console.WriteLine("Hello World!");
        }
}

Common Lisp

(write-line "Hello, World!\n")

..or..

(defun main ()
  (write-line "Hello, World!")
  0)

Fortran

PROGRAM HelloWorld
WRITE(*,*)"Hello, World!"
END PROGRAM

Go

package main
import "fmt"
func main() {
  fmt.Println("Hello, World!")
}

Groovy

println("Hello World!");

or

println "Hello World!"

Haskell

main = putStrLn "Hello World!"

Io

"Hello, world!" println

Java

class HelloWorld
{  
        public static void main(String args[])
        {
           System.out.println("Hello World!");
        }
}

Alternatively:

class HelloWorld
{  
        static
        {
           System.out.println("Hello World!");
           System.exit(0); // exit before the JVM tries to run non-existent main()
        }
}

Lua

print "Hello, world!"

OCaml

 # print_endline "Hello world!";;
 Hello world!
 - : unit = ()

Pascal

program HelloWorld;

begin
   writeln('Hello, world!');
end.

Perl

print "Hello World\n";

As PL File

print "Hello World\n";

As CGI File

#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<H1>Hello World</H1>";

PHP

<?php
echo "Hello, world!\n";
?>

PostScript

The strict equivalent to the other languages (print a string to standard output) would be:

(Hello, World!) =

However, this is not typical of how PostScript is normally used, to generate and print page images.

The following version prints a page with the "Hello, World!" message.

/Helvetica findfont % use a standard font
72 scalefont setfont % make it nice and big
100 100 moveto % someplace convenient on the page
(Hello, World!) show
showpage

Progress 4GL/ABL

display "Hello World!".

Python

print "Hello, World!"

Rexx

/* */
say "Hello, World!"

Ruby

puts "Hello, World!"

# OR
p "Hello, World!"

# OR
print "Hello, World!\n"

Scheme

(display "Hello, world!")

Seed7

$ include "seed7_05.s7i";
 
const proc: main is func
  begin
    writeln("Hello, world!");
  end func;

Tcl

puts "Hello, World!"

Turing

put "Hello, World!"

Visual Basic

Console.WriteLine("Hello, World!")

Zsh

Three forms

echo "Hello, World\!"
print "Hello, World\!"
printf "Hello, World\!\012"