"Hello, World!" program: Difference between revisions

Content deleted Content added
Accuruss (talk | contribs)
→‎Examples: deduplicate content: refer readers to the programming language’s Wikipedia articles
Line 63:
 
== Examples ==
: ''Please consult the respective programming language’s Wikipedia article for an example. Following examples are a subset of [[:Category: Programming languages with an ISO standard|programming languages with an ISO standard]].''
 
=== [[ABAP]] ===
<syntaxhighlight lang="abap">
write: 'Hello, World!'.
</syntaxhighlight>
 
=== [[Ada (programming language)|Ada]] ===
Line 82 ⟶ 78:
 
{{sxhl|2=m2|1= BEGIN DISPLAY("HELLO WORLD!") END.}}
 
=== [[ALGOL 68]] ===
 
'''begin'''
printf(($gl$,"Hello, world!"))
'''end'''
 
=== [[AppleScript]] ===
 
AppleScript is unusual in that one main mode of output is by audio message using a synthesized voice:
<syntaxhighlight lang="AppleScript">
say "Hello, world!"
</syntaxhighlight>
Alternatively, an alert window with an "OK" button can be displayed:
<syntaxhighlight lang="AppleScript">
display alert "Hello, world!"
</syntaxhighlight>
 
=== [[BASIC]] ===
Line 105 ⟶ 84:
10 PRINT "Hello, World!"
 
</syntaxhighlight>
 
=== [[Batch file]] ===
 
<syntaxhighlight lang="batch">
@echo off
echo Hello, World!
</syntaxhighlight>
 
=== [[Unix shell]] ===
 
<syntaxhighlight lang="bash">
echo "Hello, World!"
</syntaxhighlight>
 
Line 160 ⟶ 126:
</syntaxhighlight>or, using top-level statements (starting in C#v9):<ref>{{Cite web |title=Top-level statements - programs without Main methods |url=https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements |access-date=2022-09-08 |website=Microsoft Docs |language=en-us}}</ref><syntaxhighlight lang="c#">
Console.WriteLine("Hello, World!");
</syntaxhighlight>
 
=== [[Clojure]] ===
 
<syntaxhighlight lang="clojure">
(println "Hello, World!")
</syntaxhighlight>
 
Line 176 ⟶ 136:
DISPLAY 'Hello, World!'.
STOP RUN.
</syntaxhighlight>
 
=== [[D (programming language)|D]] ===
 
<syntaxhighlight lang="d">
import std.stdio;
 
void main() {
writeln("Hello, World!");
}
</syntaxhighlight>
 
=== [[Dart (programming language)|Dart]] ===
 
<syntaxhighlight lang="dart">
void main() {
print('Hello, World!');
}
</syntaxhighlight>
 
=== [[Elixir (programming language)|Elixir]] ===
 
<syntaxhighlight lang="elixir">
IO.puts("Hello, World!")
</syntaxhighlight>
 
=== [[Erlang (programming language)|Erlang]] ===
<syntaxhighlight lang="erlang">
-module(hello_world).
-export([hello/0]).
 
hello() ->
io:fwrite("Hello, World!\n").
 
</syntaxhighlight>
 
=== [[Ezhil (programming language)|Ezhil]] ===
 
<syntaxhighlight lang="ezhil">
பதிப்பி "உலகே வணக்கம்"
பதிப்பி "Hello, World!"
exit()
</syntaxhighlight>
 
=== [[F Sharp (programming language)|F#]] ===
 
<syntaxhighlight lang="f#">
printfn "Hello, World!"
</syntaxhighlight>
 
Line 238 ⟶ 150:
print *, "Hello, World!"
end program Hello
</syntaxhighlight>
 
=== [[Go (programming language)|Go]] ===
 
<syntaxhighlight lang="go">
package main
import "fmt"
 
func main() {
fmt.Println("Hello, World!")
}
</syntaxhighlight>
 
=== [[Apache Groovy|Groovy]] ===
 
<syntaxhighlight lang="groovy">
println "Hello, World!"
</syntaxhighlight>
 
=== [[Haskell (programming language)|Haskell]] ===
 
<syntaxhighlight lang="haskell">
main :: IO ()
main = putStrLn "Hello, World!"
</syntaxhighlight>
 
=== [[HTML (markup language)|HTML]] ===
<syntaxhighlight lang="html">
<p class="h1">Hello, World!</p>
</syntaxhighlight>
=== [[Java (programming language)|Java]] ===
 
<syntaxhighlight lang="java">
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
</syntaxhighlight>
 
Line 288 ⟶ 162:
</syntaxhighlight>or<syntaxhighlight lang="javascript">
alert("Hello, World!");
</syntaxhighlight>
 
=== [[Julia (programming language)|Julia]] ===
 
<syntaxhighlight lang="julia">
println("Hello, World!")
</syntaxhighlight>
 
=== [[Kotlin (programming language)|Kotlin]] ===
 
<syntaxhighlight lang="kotlin">
fun main() {
println("Hello, World!")
}
</syntaxhighlight>
 
=== [[Lisp (programming language)|Lisp]] ===
 
<syntaxhighlight lang="Lisp">
(print "Hello, World!")
</syntaxhighlight>
 
=== [[Logo (programming language)|Logo]] ===
 
print [Hello, World!]
 
=== [[LOLCODE]] ===
 
<syntaxhighlight lang="text">
HAI 1.2
CAN HAS STDIO?
VISIBLE "Hello World!"
KTHXBYE
</syntaxhighlight>
 
=== [[Lua (programming language)|Lua]] ===
 
<syntaxhighlight lang="lua">
print("Hello, World!")
</syntaxhighlight>
 
=== [[Nim (programming language)|Nim]] ===
 
<syntaxhighlight lang="nim">
echo "Hello, world!"
</syntaxhighlight>
 
=== [[Objective-C]] ===
 
<syntaxhighlight lang="objective-c">
#import <stdio.h>
 
int main() {
printf("Hello, World!\n");
}
</syntaxhighlight>
 
or, using [[NeXTSTEP]] frameworks,
 
<syntaxhighlight lang="objective-c">
#import <Foundation/Foundation.h>
 
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSLog(@"Hello, World!");
}
return 0;
}
</syntaxhighlight>
 
=== [[OCaml]] ===
 
<syntaxhighlight lang="ocaml">
print_endline "Hello, World!"
</syntaxhighlight>
 
Line 367 ⟶ 167:
 
<syntaxhighlight lang="pascal">
program Hellohello(output);
begin
writeln('Hello, World!');
end.
 
</syntaxhighlight>
 
=== [[Perl]] ===
 
<syntaxhighlight lang="perl">
print "Hello, World!\n";
</syntaxhighlight>
 
=== [[PHP]] ===
 
<syntaxhighlight lang="php">
Hello, World!
</syntaxhighlight>
 
or
 
<!-- It is conventional to not have a trailing ?> in PHP files, so please do not reädd -->
<syntaxhighlight lang="php">
<?php
echo 'Hello, World!';
</syntaxhighlight>
 
=== [[PostScript]] ===
 
<syntaxhighlight lang="postscript">
%!PS
/Times-Roman findfont 12 scalefont setfont
100 200 moveto
(Hello World!) show
showpage
</syntaxhighlight>
 
=== [[PowerShell]] ===
 
<syntaxhighlight lang="powershell">
'Hello, World!'
</syntaxhighlight>
 
Line 414 ⟶ 177:
<syntaxhighlight lang="prolog">
main() :- write("Hello, World!"), nl.
</syntaxhighlight>
 
=== [[Python (programming language)|Python]] ===
 
<syntaxhighlight lang="python">
print("Hello, World!")
</syntaxhighlight>
 
=== [[R (programming language)|R]] ===
 
<syntaxhighlight lang="r">
print("Hello, World!")
</syntaxhighlight>
 
=== [[Racket (programming language)|Racket]] ===
 
<syntaxhighlight lang="racket">
#lang racket
(displayln "Hello, World!")
</syntaxhighlight>
 
Line 439 ⟶ 183:
<syntaxhighlight lang="ruby">
puts "Hello, World!"
</syntaxhighlight>
 
=== [[Rust (programming language)|Rust]] ===
 
<syntaxhighlight lang="rust">
fn main() {
println!("Hello, World!");
}
</syntaxhighlight>
 
=== [[Scratch (programming language)|Scratch]] ===
A [[Visual programming language|visual script]] that has a [[Sprite (computer graphics)|sprite]] say "Hello, World!" when the start flag is clicked:
:[[File:Scratch Hello World.png|left|alt=Three step Scratch program: 1. When "green flag" clicked then 2. Say "Hello, world!" then 3. Stop "this script".]]{{clear}}
 
=== [[Simula]] ===
 
'''Begin'''
'''OutText''' ("Hello, World!");
'''Outimage''';
'''End''';
 
=== [[Smalltalk]] ===
 
<syntaxhighlight lang="smalltalk">
Transcript show: 'Hello, World!'.
</syntaxhighlight>
 
=== [[Standard ML]] ===
 
<syntaxhighlight lang="sml">
print "Hello, World!\n"
</syntaxhighlight>
 
=== [[Swift (programming language)|Swift]] ===
 
<syntaxhighlight lang="swift">
print("Hello, World!")
</syntaxhighlight>
 
=== [[Tcl]] ===
 
<syntaxhighlight lang="tcl">
puts "Hello, World!"
</syntaxhighlight>
 
=== [[TI-BASIC]] ===
 
<syntaxhighlight lang="basic">
:Disp "HELLO, WORLD!"
</syntaxhighlight>
 
=== [[VBScript]] ===
 
<syntaxhighlight lang="vbscript">
WScript.Echo "Hello, World!"
</syntaxhighlight>
 
=== [[Visual Basic .NET]] ===
<syntaxhighlight lang="vb.net">
Imports System
 
Module Program
Sub Main
Console.WriteLine("Hello, World!")
End Sub
End Module
 
 
</syntaxhighlight>
 
=== [[WebAssembly|WebAssembly Text Format]] ===
 
<syntaxhighlight lang="wat">
(module
(import "console" "log" (func $log (param i32) (param i32)))
(import "js" "mem" (memory 1))
(data (i32.const 0) "Hello World") ;; string written to global memory
(func (export "helloWorld")
i32.const 0
i32.const 11
call $log
)
)
</syntaxhighlight>
 
=== [[X86 assembly language|x86 Assembly]] ===
<syntaxhighlight lang="nasm">
SECTION .data
Msg: db "Hello world!", 10
Len: equ $-Msg
 
SECTION .text
global _start
_start:
mov eax,4
mov ebx,1
mov ecx,Msg
mov edx,Len
int 80H
 
mov eax,1
mov ebx,0
int 80H
</syntaxhighlight>
 
=== [[Zig (programming language)|Zig]] ===
<syntaxhighlight lang="zig">
const std = @import("std");
 
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try stdout.print("Hello, {s}!\n", .{"world"});
}
 
</syntaxhighlight>