Kurz: Das erste Beispielprogramm aus jedem Kurs – mit der echten Ausgabe – zum direkten Vergleich der Syntax von 42 Programmiersprachen.
Ada
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
begin
Put_Line ("Hallo, Welt!");
Put ("ohne Zeilenumbruch");
New_Line;
Put_Line ("1 + 2 =" & Integer'Image (1 + 2));
end Main;Ausgabe:
Hallo, Welt!
ohne Zeilenumbruch
1 + 2 = 3Weiter: Ada-Kurs
Assembler (x86-64)
section .data
text db "Hallo, Welt!", 10 ; 10 = Zeilenumbruch
laenge equ $ - text ; Länge berechnen
section .text
global _start
_start:
mov rax, 1 ; Systemaufruf Nr. 1: write
mov rdi, 1 ; Ziel: Dateideskriptor 1 = stdout
mov rsi, text ; Adresse des Textes
mov rdx, laenge ; Anzahl der Bytes
syscall ; Kernel aufrufen
mov rax, 60 ; Systemaufruf Nr. 60: exit
xor rdi, rdi ; Rückgabewert 0
syscallAusgabe:
Hallo, Welt!Weiter: Assembler (x86-64)-Kurs
AWK
BEGIN {
print "Hallo, Welt!"
print "1 + 2 =", 1 + 2
printf "%s hat %d Punkte\n", "Mia", 17
x = 10
y = x * 2
print x, y
}Ausgabe:
Hallo, Welt!
1 + 2 = 3
Mia hat 17 Punkte
10 20Weiter: AWK-Kurs
C
#include <stdio.h>
int main(void) {
printf("Hallo, Welt!\n");
return 0;
}Ausgabe:
Hallo, Welt!Weiter: C-Kurs
C#
Console.WriteLine("Hallo, Welt!");Ausgabe:
Hallo, Welt!Weiter: C#-Kurs
C++
#include <iostream>
int main() {
std::cout << "Hallo, Welt!" << std::endl;
return 0;
}Ausgabe:
Hallo, Welt!Weiter: C++-Kurs
COBOL
IDENTIFICATION DIVISION.
PROGRAM-ID. HALLO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 NAME PIC X(20) VALUE "Mia".
01 ALTERSJAHRE PIC 99 VALUE 17.
PROCEDURE DIVISION.
DISPLAY "Hallo COBOL!".
DISPLAY "Name: " NAME.
DISPLAY "Alter: " ALTERSJAHRE.
STOP RUN.Ausgabe:
Hallo COBOL!
Name: Mia
Alter: 17Weiter: COBOL-Kurs
Common Lisp
(format t "Hallo, Welt!~%")
(format t "1 + 2 = ~a~%" (+ 1 2))
(print "mit print")
(terpri)
(princ "ohne Anführungszeichen")
(terpri)Ausgabe:
Hallo, Welt!
1 + 2 = 3
"mit print"
ohne AnführungszeichenWeiter: Common Lisp-Kurs
Dart
void main() {
print('Hallo Dart!');
var name = 'Mia';
print('Hallo, $name!');
print('2 + 3 = ${2 + 3}');
print('Länge: ${name.length}');
print("Doppelte Anführungszeichen gehen auch");
}Ausgabe:
Hallo Dart!
Hallo, Mia!
2 + 3 = 5
Länge: 3
Doppelte Anführungszeichen gehen auchWeiter: Dart-Kurs
Elixir
IO.puts("Hallo Elixir!")
name = "Mia"
IO.puts("Hallo, #{name}!")
IO.inspect([1, 2, 3])
IO.inspect(%{a: 1, b: "zwei"})
IO.puts(2 + 3)
IO.write("ohne Zeilenumbruch")
IO.puts("")Ausgabe:
Hallo Elixir!
Hallo, Mia!
[1, 2, 3]
%{a: 1, b: "zwei"}
5
ohne ZeilenumbruchWeiter: Elixir-Kurs
Erlang
main(_) ->
io:format("Hallo, Welt!~n"),
io:format("1 + 2 = ~p~n", [1 + 2]),
io:format("~s hat ~w Punkte~n", ["Mia", 17]),
io:put_chars("ohne Zeilenumbruch"),
io:nl(),
X = 42,
io:format("X = ~p~n", [X]).Ausgabe:
Hallo, Welt!
1 + 2 = 3
Mia hat 17 Punkte
ohne Zeilenumbruch
X = 42Weiter: Erlang-Kurs
F#
printfn "Hallo, Welt!"
printfn "1 + 2 = %d" (1 + 2)
printf "ohne Zeilenumbruch"
printfn ""
let name = "Mia"
printfn "Hallo, %s!" name
printfn $"Interpoliert: {name} hat {name.Length} Buchstaben"
printfn "%s ist %d Jahre alt und %.1f m groß" name 17 1.68Ausgabe:
Hallo, Welt!
1 + 2 = 3
ohne Zeilenumbruch
Hallo, Mia!
Interpoliert: Mia hat 3 Buchstaben
Mia ist 17 Jahre alt und 1.7 m großWeiter: F#-Kurs
Fortran
program hallo
implicit none ! alle Variablen müssen deklariert werden
character(len=20) :: name
integer :: alter
name = "Mia"
alter = 17
print *, "Hallo Fortran!"
print *, "Name: ", trim(name), ", Alter: ", alter
write(*, "(a, i0)") "Alter nächstes Jahr: ", alter + 1
end program halloAusgabe:
Hallo Fortran!
Name: Mia, Alter: 17
Alter nächstes Jahr: 18Weiter: Fortran-Kurs
Go
package main
import "fmt"
func main() {
fmt.Println("Hallo, Welt!")
}Ausgabe:
Hallo, Welt!Weiter: Go-Kurs
Groovy
println "Hallo, Welt!"
println("1 + 2 = ${1 + 2}")
print "ohne Zeilenumbruch"
println ""
def name = "Mia"
println "Hallo, $name! Dein Name hat ${name.length()} Buchstaben."
println 'Einfache Anführungszeichen ersetzen nichts: $name'
println """Mehrzeiliger
Text mit ${name}"""Ausgabe:
Hallo, Welt!
1 + 2 = 3
ohne Zeilenumbruch
Hallo, Mia! Dein Name hat 3 Buchstaben.
Einfache Anführungszeichen ersetzen nichts: $name
Mehrzeiliger
Text mit MiaWeiter: Groovy-Kurs
Haskell
main :: IO ()
main = do
putStrLn "Hallo Haskell!"
putStrLn ("2 + 3 = " ++ show (2 + 3))
print (length "Haskell")
print [1, 2, 3]
print "Text mit Anführungszeichen"Ausgabe:
Hallo Haskell!
2 + 3 = 5
7
[1,2,3]
"Text mit Anf\252hrungszeichen"Weiter: Haskell-Kurs
Java
public class Hallo {
public static void main(String[] args) {
System.out.println("Hallo, Welt!");
}
}Ausgabe:
Hallo, Welt!Weiter: Java-Kurs
JavaScript
console.log("Hallo, Welt!");
console.log("Ich lerne JavaScript.");Ausgabe:
Hallo, Welt!
Ich lerne JavaScript.Weiter: JavaScript-Kurs
Julia
println("Hallo Julia!")
name = "Mia"
println("Hallo, $(name)!")
println("2 + 3 = ", 2 + 3)
println("Interpolation: $(2 * 21) und $(uppercase(name))")
print("ohne Zeilenumbruch")
print("\n")
@show name
@show 1 + 1Ausgabe:
Hallo Julia!
Hallo, Mia!
2 + 3 = 5
Interpolation: 42 und MIA
ohne Zeilenumbruch
name = "Mia"
1 + 1 = 2Weiter: Julia-Kurs
Kotlin
fun main() {
println("Hallo Kotlin!")
print("ohne Zeilenumbruch")
println()
val name = "Mia"
println("Hallo $name, 2 + 3 = ${2 + 3}")
}Ausgabe:
Hallo Kotlin!
ohne Zeilenumbruch
Hallo Mia, 2 + 3 = 5Weiter: Kotlin-Kurs
Lua
print("Hallo Lua!")
local name = "Mia"
print("Hallo, " .. name .. "!")
print("Zahl:", 42, "Wahrheitswert:", true)
io.write("ohne Zeilenumbruch")
io.write("\n")
print(string.format("%s ist %d Jahre alt", name, 17))Ausgabe:
Hallo Lua!
Hallo, Mia!
Zahl: 42 Wahrheitswert: true
ohne Zeilenumbruch
Mia ist 17 Jahre altWeiter: Lua-Kurs
MATLAB
disp('Hallo MATLAB!')
x = 5
y = x ^ 2; % Semikolon unterdrückt die Ausgabe
y
fprintf('x = %d, y = %d\n', x, y);
a = 3; b = 4;
c = sqrt(a^2 + b^2)Ausgabe:
Hallo MATLAB!
x = 5
y = 25
x = 5, y = 25
c = 5Weiter: MATLAB-Kurs
Nim
echo "Hallo, Welt!"
echo "1 + 2 = ", 1 + 2
stdout.write "ohne Zeilenumbruch"
stdout.write "\n"
let name = "Mia"
echo "Hallo, ", name, "!"
echo "Länge: ", name.lenAusgabe:
Hallo, Welt!
1 + 2 = 3
ohne Zeilenumbruch
Hallo, Mia!
Länge: 3Weiter: Nim-Kurs
OCaml
let () =
print_endline "Hallo, Welt!";
Printf.printf "1 + 2 = %d\n" (1 + 2);
print_string "ohne Zeilenumbruch";
print_newline ()Ausgabe:
Hallo, Welt!
1 + 2 = 3
ohne ZeilenumbruchWeiter: OCaml-Kurs
Pascal
program Hallo;
begin
writeln('Hallo, Welt!');
writeln('1 + 2 = ', 1 + 2);
write('ohne Zeilenumbruch');
writeln;
end.Ausgabe:
Hallo, Welt!
1 + 2 = 3
ohne ZeilenumbruchWeiter: Pascal-Kurs
Perl
#!/usr/bin/perl
use strict; # Variablen müssen deklariert werden
use warnings; # Warnungen bei verdächtigem Code
use utf8; # Quelltext ist UTF-8
binmode(STDOUT, ":utf8"); # Ausgabe als UTF-8
my $name = "Mia";
print "Hallo, $name!\n";
print 'Einfache Quotes ersetzen nichts: $name', "\n";
printf("%s ist %d Jahre alt\n", $name, 17);
say_hallo();
sub say_hallo { print "Hallo aus einer Funktion\n"; }Ausgabe:
Hallo, Mia!
Einfache Quotes ersetzen nichts: $name
Mia ist 17 Jahre alt
Hallo aus einer FunktionWeiter: Perl-Kurs
PHP
<?php
$name = "Mia";
echo "Hallo $name!\n";
echo 'Einfache Anführungszeichen ersetzen keine Variablen: $name', "\n";
print("print geht auch\n");Ausgabe:
Hallo Mia!
Einfache Anführungszeichen ersetzen keine Variablen: $name
print geht auchWeiter: PHP-Kurs
PowerShell
Write-Output "Hallo PowerShell!"
$name = "Mia"
Write-Output "Hallo, $name!"
"Ausdruck wird direkt ausgegeben: $(2 + 3)"
Write-Host "Write-Host schreibt direkt auf die Konsole"
2 + 3
$PSVersionTable.PSVersion.Major -ge 5Ausgabe:
Hallo PowerShell!
Hallo, Mia!
Ausdruck wird direkt ausgegeben: 5
Write-Host schreibt direkt auf die Konsole
5
TrueWeiter: PowerShell-Kurs
Prolog
main :-
write('Hallo, Welt!'), nl,
X is 1 + 2,
format("1 + 2 = ~w~n", [X]),
print(42), nl,
format("~a hat ~d Punkte~n", [mia, 17]).Ausgabe:
Hallo, Welt!
1 + 2 = 3
42
mia hat 17 PunkteWeiter: Prolog-Kurs
Python
print("Hallo, Welt!")
print("Python macht Spaß")
print(2 + 3)Ausgabe:
Hallo, Welt!
Python macht Spaß
5Weiter: Python-Kurs
R
print("Hallo R!")
name <- "Mia"
cat("Hallo,", name, "\n")
cat("2 + 3 =", 2 + 3, "\n")
paste("Hallo", name)
x <- 42
xAusgabe:
[1] "Hallo R!"
Hallo, Mia
2 + 3 = 5
[1] "Hallo Mia"
[1] 42Weiter: R-Kurs
Racket
#lang racket
(displayln "Hallo, Welt!")
(printf "1 + 2 = ~a~n" (+ 1 2))
(display "ohne Zeilenumbruch")
(newline)
(println "println zeigt Anführungszeichen")
(write "write auch")
(newline)
(define name "Mia")
(displayln (string-append "Hallo, " name "!"))
(displayln (format "~a hat ~a Punkte" name 17))Ausgabe:
Hallo, Welt!
1 + 2 = 3
ohne Zeilenumbruch
"println zeigt Anführungszeichen"
"write auch"
Hallo, Mia!
Mia hat 17 PunkteWeiter: Racket-Kurs
Ruby
puts "Hallo Ruby!"
name = "Mia"
puts "Hallo, #{name}!"
print "ohne Zeilenumbruch"
puts
p "p zeigt Debug-Darstellung"Ausgabe:
Hallo Ruby!
Hallo, Mia!
ohne Zeilenumbruch
"p zeigt Debug-Darstellung"Weiter: Ruby-Kurs
Rust
fn main() {
println!("Hallo, Welt!");
}Ausgabe:
Hallo, Welt!Weiter: Rust-Kurs
Scala
@main def main(): Unit =
println("Hallo Scala!")
val name = "Mia"
println(s"Hallo, $name!") // s-Interpolation
println(s"2 + 3 = ${2 + 3}")
println(f"Pi ist ungefähr ${math.Pi}%.3f") // f-Interpolation mit Format
print("ohne Zeilenumbruch")
println()Ausgabe:
Hallo Scala!
Hallo, Mia!
2 + 3 = 5
Pi ist ungefähr 3.142
ohne ZeilenumbruchWeiter: Scala-Kurs
Scheme
(display "Hallo, Welt!")
(newline)
(display (+ 1 2))
(newline)
(write "write zeigt Anführungszeichen")
(newline)
(display (list 1 "zwei" 'drei 4.5))
(newline)
(write (list 1 "zwei" 'drei #\x))
(newline)
(define name "Mia")
(display (string-append "Hallo, " name "!"))
(newline)Ausgabe:
Hallo, Welt!
3
"write zeigt Anf\xfchrungszeichen"
(1 zwei drei 4.5)
(1 "zwei" drei #\x)
Hallo, Mia!Weiter: Scheme-Kurs
SQL
SELECT 'Hallo SQL' AS gruss, 6 * 7 AS antwort;Ausgabe:
gruss antwort
--------- -------
Hallo SQL 42Weiter: SQL-Kurs
Swift
print("Hallo Swift!")
let name = "Mia"
print("Hallo, \(name)!")
print("2 + 3 =", 2 + 3)
print("Mehrere", "Werte", separator: "-", terminator: "!\n")Ausgabe:
Hallo Swift!
Hallo, Mia!
2 + 3 = 5
Mehrere-Werte!Weiter: Swift-Kurs
Tcl
puts "Hallo, Welt!"
set name "Mia"
puts "Hallo, $name!"
puts "1 + 2 = [expr {1 + 2}]"
puts -nonewline "ohne Zeilenumbruch"
puts ""
puts stdout "auf stdout"Ausgabe:
Hallo, Welt!
Hallo, Mia!
1 + 2 = 3
ohne Zeilenumbruch
auf stdoutWeiter: Tcl-Kurs
TypeScript
function flaeche(breite: number, hoehe: number): number {
return breite * hoehe;
}
console.log(flaeche(3, 4));Ausgabe:
12Weiter: TypeScript-Kurs
Visual Basic .NET
Module Program
Sub Main()
Console.WriteLine("Hallo, Welt!")
Console.WriteLine("1 + 2 = " & (1 + 2))
Console.Write("ohne Zeilenumbruch")
Console.WriteLine()
Dim name As String = "Mia"
Console.WriteLine("Hallo, " & name & "!")
Console.WriteLine($"Interpoliert: {name} hat {name.Length} Buchstaben")
Console.WriteLine("{0} ist {1} Jahre alt", name, 17)
End Sub
End ModuleAusgabe:
Hallo, Welt!
1 + 2 = 3
ohne Zeilenumbruch
Hallo, Mia!
Interpoliert: Mia hat 3 Buchstaben
Mia ist 17 Jahre altWeiter: Visual Basic .NET-Kurs
Zig
const std = @import("std");
pub fn main() !void {
const out = std.io.getStdOut().writer();
try out.print("Hallo, {s}!\n", .{"Zig"});
try out.print("2 + 3 = {d}\n", .{2 + 3});
try out.writeAll("Zeile ohne Format\n");
}Ausgabe:
Hallo, Zig!
2 + 3 = 5
Zeile ohne FormatWeiter: Zig-Kurs