Hello world

บทความนี้มีชื่อเป็นภาษาอังกฤษ เนื่องจากยังไม่มีชื่อภาษาไทยที่กระชับ เหมาะสม หรือไม่รู้วิธีอ่านในภาษาไทย

Hello world (เฮลโลเวิลด์) เป็นคำที่ใช้ในภาษาโปรแกรมที่แสดงผลออกมาคำว่า "Hello world" หรือ "Hello, world!" (ตามหลักภาษาอังกฤษ) นิยมใช้ในการเรียนการสอนซึ่งนักเรียนจะได้เขียนโปรแกรม hello world เป็นโปรแกรมแรก

โปรแกรมเฮลโลเวิลด์โปรแกรมแรกเกิดขึ้น จากหนังสือการเขียนโปรแกรมภาษาซี แต่งโดยไบรอัน เคอร์นิงแฮน และ เดนนิส ริตชี ตีพิมพ์ในปี พ.ศ. 2521 (ค.ศ. 1978) โดยตัวอย่างโปรแกรมมาจาก กระดาษจดข้อมูลของไบรอันขณะที่ทำงานที่ เบลล์แล็บ (Bell Laboratories) ปี พ.ศ. 2517 (ค.ศ. 1974) ตัวอย่างในหนังสือ พิมพ์ข้อความว่า "hello, world" (โดย ไม่มีตัวพิมพ์ใหญ่ และเครื่องหมายตกใจ ซึ่งได้เพิ่มมาในภายหลัง) โดยแสดงข้อความ:

 main ( ) {
     printf ("hello, world!") ;
 }

การเขียนคำนี้ มีการใช้งานโดยเขียนหลายแบบคือ ตัวอักษร H ใหญ่ และ h เล็ก ขณะเดียวกับ W ใหญ่ และ w เล็ก รวมถึงการเขียนเครื่องหมาย และแบบไม่มีเครื่องหมาย

การเขียนชุดคำสั่งนี้ในขณะที่บางโปรแกรมสามารถใช้คำสั่งได้อย่างเรียบง่าย ในขณะที่บางโปรแกรมต้องใช้คำสั่งซับซ้อนในการแสดงผล โดยเฉพาะอย่างยิ่งที่ใช้GUI โปรแกรมเฮลโลเวิลด์มีประโยชน์ในการทดสอบว่าคอมไพเลอร์และส่วนต่างๆหลักของโปรแกรมทำงานได้ การรวบรวมคำสั่ง "hello world" ในภาษาโปรแกรมต่างๆ ถูกใช้ในการช่วยเรียน และการเปรียบเทียบการใช้งานของภาษาต่างๆ

เนื้อหา

[แก้] ตัวอย่างของ Hello world ในภาษาโปรแกรมต่างๆ

[แก้] 4GL - Computer Associates with Ingres/DB

message "Hello, World!" with style = popup;

[แก้] ABAP - SAP AG

REPORT ZELLO.
WRITE 'Hello, World!'.

[แก้] ABC

WRITE "Hello, world!"

[แก้] Ada

with Ada.Text_IO;

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

For explanation see wikibooks:Ada Programming:Basic.

[แก้] ALGOL 68

In the popular upper-case stropping convention for bold words:

BEGIN
    print (("Hello, World!", newline))
END

or using prime stropping suitable for punch cards:

'BEGIN'
    PRINT (("HELLO, WORLD!", NEWLINE))
'END'

or minimally using the short form of begin and end, and implied newline at program termination:

( print ("Hello, World!") )

[แก้] AmigaE

PROC main ()
   WriteF ('Hello, World!') ;
ENDPROC

[แก้] APL

'Hello World'

[แก้] AppleScript

See also GUI section.

return "Hello World!"

[แก้] ASP

<%
Response.Write ("Hello World")
%>
or simply:
<%="Hello World" %>

[แก้] ASP.NET

Response.Write ("Hello World")

[แก้] Assembly language

[แก้] Accumulator-only architecture: DEC PDP-8, PAL-III assembler

See the example section of the PDP-8 article.

[แก้] First successful µP/OS combinations: Intel 8080/Zilog Z80, CP/M, RMAC assembler

bdos    equ    0005H    ; BDOS entry point
start:  mvi    c,9      ; BDOS function: output string
        lxi    d,msg$   ; address of msg
        call   bdos
        ret             ; return to CCP

msg$:   db    'Hello, world!$'
end     start

[แก้] Accumulator + index register machine: MOS Technology 6502, CBM KERNAL, ca65 assembler

MSG:   .ASCIIZ "Hello, world!"
        LDX    #$F3
@LP:    LDA    MSG-$F3,X ; load character
        JSR    $FFD2     ; CHROUT (KERNAL) , output to current output device (screen)
        INX
        BNE    @LP       ; 
        RTS

[แก้] Accumulator/Index microcoded machine: Data General Nova, RDOS

See the example section of the Nova article.

[แก้] Expanded accumulator machine: Intel x86, DOS, TASM

MODEL   SMALL
IDEAL
STACK   100H

DATASEG
        MSG DB 'Hello, world!', 13, '$'

CODESEG
Start:
        MOV AX, @data
        MOV DS, AX
        MOV DX, OFFSET MSG
        MOV AH, 09H      ; DOS: output ASCII$ string
        INT 21H
        MOV AX, 4C00H
        INT 21H
        END Start

[แก้] Expanded accumulator machine: Intel x86, Microsoft Windows, FASM

;Assumes that enviromnent variable %fasminc% is set
format PE GUI 4.0
include '%fasminc%\win32a.inc'
section '.code' code readable executable
invoke MessageBox,0,hellomsg,hellolb,MB_OK+MB_ICONINFORMATION
invoke ExitProcess,0
section '.data' data readable writable
hellomsg db 'Hello, World!',0
hellolb db 'Hello World',0
data import
library user32,'user32.dll',kernel32,'kernel32.dll'
include '%fasminc%\apia\user32.inc'
include '%fasminc%\apia\kernel32.inc'
end data

[แก้] Expanded accumulator machine: Intel x86, Linux, GAS

.data
msg:
    .ascii     "Hello, world!\n"
    len = . - msg
.text
    .global _start
_start:
    movl        $len,%edx
    movl        $msg,%ecx
    movl        $1,%ebx
    movl        $4,%eax
    int $0x80
    movl        $0,%ebx
    movl        $1,%eax
    int $0x80

[แก้] General-purpose fictional computer: MIX, MIXAL

TERM    EQU    19          console device no. (19 = typewriter)
        ORIG   1000        start address
START   OUT    MSG (TERM)   output data at address MSG
        HLT                halt execution
MSG     ALF    "HELLO"
        ALF    " WORL"
        ALF    "D    "
        END    START       end of program

[แก้] General-purpose fictional computer: MMIX, MMIXAL

string  BYTE   "Hello, world!",#a,0   string to be printed (#a is newline and 0 terminates the string)
  Main  GETA   $255,string            get the address of the string in register 255
        TRAP   0,Fputs,StdOut         put the string pointed to by register 255 to file StdOut
        TRAP   0,Halt,0               end process

[แก้] General-purpose-register CISC: DEC PDP-11, RT-11, MACRO-11

.MCALL  .REGDEF,.TTYOUT,.EXIT
        .REGDEF

HELLO:  MOV    #ffffff,R1
        MOVB   (R1) ,R0
LOOP:  .TTYOUT
        MOVB  + (R1) ,R0
        BNE    LOOP
       .EXIT

MSG:   .ASCIZ  /HELLO, WORLD!/
       .END    HELLO

[แก้] CISC on advanced multiprocessing OS: DEC VAX, VMS, MACRO-32

        .title    hello

        .psect    data, wrt, noexe

chan:   .blkw     1
iosb:   .blkq     1
term:   .ascid    "SYS$OUTPUT"
msg:    .ascii    "Hello, world!"
len =   . - msg

        .psect    code, nowrt, exe

        .entry    hello, ^m<>

        ; Establish a channel for terminal I/O
        $assign_s devnam=term, -
                  chan=chan
        blbc      r0, end

        ; Queue the I/O request
        $qiow_s   chan=chan, -
                  func=#io$_writevblk, -
                  iosb=iosb, -
                  p1=msg, -
                  p2=#f1ffff

        ; Check the status and the IOSB status
        blbc      r0, end
        movzwl    iosb, r0

        ; Return to operating system
end:    ret

       .end       hello

[แก้] RISC processor: ARM, RISC OS, BBC BASIC's in-line assembler

.program         
         ADR R0,message
         SWI "OS_Write0"
         SWI "OS_Exit"
.message         
         DCS "Hello, world!"
         DCB 0
          ALIGN

หรือเวอร์ชันย่อ (จาก qUE) ;

         SWI"OS_WriteS":EQUS"Hello, world!":EQUB0:ALIGN:MOVPC,R14

[แก้] AutoHotkey

MsgBox, "Hello, World!"

[แก้] Autoit

MsgBox (1,'','Hello, world!') 

[แก้] AWK

BEGIN { print "Hello, world!" }

[แก้] Bash

echo Hello,\ world!

[แก้] BASIC

[แก้] General

The following example works for any ANSI/ISO-compliant BASIC implementation, as well as most implementations built into or distributed with microcomputers in the 1970s and 1980s (usually some variant of Microsoft BASIC) :

10 PRINT "Hello, world!"
20 END

Such implementations of BASIC could also execute instructions in an immediate mode when line numbers are omitted. The following examples work without requiring a RUN instruction.

PRINT "Hello, world!"
? "Hello, world!"

Later implementations of BASIC allowed greater support for structured programming and did not require line numbers for source code. The following example works when RUN for the vast majority of modern BASICs.

PRINT "Hello, world!"
END

Again, the "END" statement is optional in many BASICs.

[แก้] PBASIC

DEBUG "Hello, world!", CR

or, the typical microcontroller Hello World program equivalent with the only output device present being a light-emitting diode (LED) (in this case attached to the seventh output pin) :

DO
    HIGH 7 'Make the 7th pin go high (turn the LED on)
    PAUSE 500 'Sleep for half a second
    LOW 7 ' Make the 7th pin go low (turn the LED off)
    PAUSE 500 'Sleep for half a second
LOOP
END

[แก้] StarOffice/OpenOffice Basic

sub main
    print "Hello, World"
end sub

[แก้] TI-BASIC

On TI calculators of the TI-80 through TI-86 range:

:Disp "HELLO, WORLD!"           or
:Output (x,y,"HELLO, WORLD!")    or
:Text (x,y,"HELLO, WORLD!")      or
:Text (-1,x,y,"HELLO, WORLD!")   ;only on the 83+ and higher

or simply

:"HELLO, WORLD!"

On TI-89/TI-92 (+) /Voyage 200 calculators:

:hellowld ()
:Prgm
:Disp "Hello, world!"
:EndPrgm

[แก้] Visual Basic

Sub Main
  MsgBox "Hello World!"
End Sub

[แก้] Visual Basic .NET

Module HelloWorldApp
  Sub Main ()
     System.Console.WriteLine ("Hello, world!")
  End Sub
End Module

or, defined differently,

Class HelloWorldApp
  Shared Sub Main ()
     System.Console.WriteLine ("Hello, world!")
  End Sub
End Class

[แก้] Blitz BASIC

Print "Hello, World!"

[แก้] DarkBASIC

PRINT "HELLO WORLD"
TEXT 0,0,"Hello World"
WAIT KEY

[แก้] BCPL

GET "LIBHDR"

LET START () BE
$ (
    WRITES ("Hello, world!*N")
$)

[แก้] BLISS

%TITLE 'HELLO_WORLD'
MODULE HELLO_WORLD (IDENT='V1.0', MAIN=HELLO_WORLD,
        ADDRESSING_MODE (EXTERNAL=GENERAL)) =
BEGIN

    LIBRARY 'SYS$LIBRARY:STARLET';

    EXTERNAL ROUTINE
       LIB$PUT_OUTPUT;

GLOBAL ROUTINE HELLO_WORLD =
BEGIN

    LIB$PUT_OUTPUT (%ASCID %STRING ('Hello World!'))
END;

END
ELUDOM

[แก้] boo

See also GUI Section.

print "Hello, world!"


[แก้] Casio FX-9750

This program will work on the fx-9750 graphing calculator and compatibles.

"HELLO WORLD"

[แก้] C

#fff3f2e <stdio.h>

int main (void)
{
   puts ("Hello, world!") ;
   return 0;
}

[แก้] Ch

The above C code can run in Ch as examples. The simple one in Ch is:

 printf ("Hello, world\n") ;


[แก้] C#

See also GUI Section.

class HelloWorldApp
{
    static void Main ()
    {
        System.Console.WriteLine ("Hello, world!") ;
    }
}

[แก้] C++

#fff3f2e <iostream>

int main ()
{
    std::cout << "Hello, world!\n";
}

[แก้] C++/CLI

int main ()
{
   System::Console::WriteLine ("Hello, world!") ;
}

[แก้] C++, Managed (.NET)

#ffffff <mscorlib.dll>

using namespace System;

int wmain ()
{
    Console::WriteLine ("Hello, world!") ;
}

[แก้] ColdFusion (CFM)

<cfoutput>Hello, world!</cfoutput>

[แก้] COMAL

PRINT "Hello, World!"

[แก้] CIL

.method public static void Main () cil managed
{
     .entrypoint
     .maxstack 8
     ldstr "Hello, world!"
     call void [mscorlib]System.Console::WriteLine (string)
     ret
}

[แก้] Clean

module hello

Start = "Hello, world"

[แก้] CLIST

PROC 0
WRITE Hello, World!

[แก้] Clipper

@1,1 say "Hello World!"

[แก้] COBOL

IDENTIFICATION DIVISION.
PROGRAM-ID.     HELLO-WORLD.

ENVIRONMENT DIVISION.

DATA DIVISION.

PROCEDURE DIVISION.
DISPLAY "Hello, world!".
STOP RUN.


[แก้] D

import std.stdio;
void main ()
{
    writefln ("Hello, world!") ;
}

[แก้] DC an arbitrary precision calculator

[Hello, world!]p

[แก้] DCL batch

$ write sys$output "Hello, world!"

[แก้] DOLL

// The program is itself an object. The program "this" object can be overloaded
// as a function that work as "main" function in a C program.
this ()
{
    system.stdout ("Hello, World!") ;
}

[แก้] Dylan

module: hello

format-out ("Hello, world!\n") ;

[แก้] Ed and Ex (Ed extended)

a
hello world!
.
p

[แก้] Eiffel

class HELLO_WORLD

creation
    make
feature
    make is
    local
            io:BASIC_IO
    do
            !!io
            io.put_string ("%N Hello, world!")
    end -- make
end -- class HELLO_WORLD

[แก้] Erlang

-module (hello).
-export ([hello_world/0]).

hello_world () -> io:fwrite ("Hello, world!\n").

[แก้] Euphoria

puts (1, "Hello, world!")

[แก้] F#

print_endline "Hello world"

[แก้] Factor

"Hello world" print

[แก้] filePro

@once
   mesgbox "Hello, world!"
   exit

[แก้] Fjölnir

"hello" < main
{
   main ->
   stef (;)
   stofn
       skrifastreng (;"Halló Veröld!") ,
   stofnlok
}
*
"GRUNNUR"
;

[แก้] FOCAL

type "Hello, World!",!

or

t "Hello, World!",!

[แก้] Focus

-TYPE Hello World

[แก้] Forte TOOL

begin TOOL HelloWorld;

includes Framework;
HAS PROPERTY IsLibrary = FALSE;

forward  Hello;

-- START CLASS DEFINITIONS

class Hello inherits from Framework.Object

has public  method Init;

has property
    shared= (allow=off, override=on) ;
    transactional= (allow=off, override=on) ;
    monitored= (allow=off, override=on) ;
    distributed= (allow=off, override=on) ;

end class;
-- END CLASS DEFINITIONS

-- START METHOD DEFINITIONS

------------------------------------------------------------
method Hello.Init
begin
super.Init () ;

task.Part.LogMgr.PutLine ('HelloWorld!') ;
end method;
-- END METHOD DEFINITIONS
HAS PROPERTY
    CompatibilityLevel = 0;
    ProjectType = APPLICATION;
    Restricted = FALSE;
    MultiThreaded = TRUE;
    Internal = FALSE;
    LibraryName = 'hellowor';
    StartingMethod = (class = Hello, method = Init) ;

end HelloWorld;

[แก้] Forth

: halloforth ( -- ) ." Hello, world!" CR ;

[แก้] FORTRAN

   PROGRAM HELLO
     PRINT *, 'Hello, world!'
   END

[แก้] Fril

 ? ((pp "Hello, world!"))

[แก้] Frink

println["Hello, world!"]

[แก้] Gambas

See also GUI section.

PUBLIC SUB Main ()
  Print "Hello, world!"
END

[แก้] Game Maker

In the draw event of some object:

draw_text (x,y,"Hello World")

Or to show a splash screen message:

show_message ("Hello World")

[แก้] Haskell

module Main (main) where

main = putStr "Hello World\n"

or

main = putStr "Hello World\n"

[แก้] Heron

program HelloWorld;
functions {
  _main () {
    print_string ("Hello, world!") ;
  }
}
end

[แก้] HP-41 & HP-42S

(Handheld Hewlett-Packard RPN-based alphanumeric engineering calculators.)

01 LBLTHELLO

02 THELLO, WORLD

03 PROMPT

HP-41 output

[แก้] HyperTalk (Apple HyperCard's scripting programming language)

put "Hello world"

ภาพ:Hworld.gif

or

Answer "Hello World"

[แก้] IDL

print,"Hello world!"

[แก้] Inform

[ Main;
  print "Hello, world!^";
];

[แก้] Io

"Hello world!" print

or

write ("Hello world!\n")

[แก้] Iptscrae

ON ENTER {
    "Hello, " "World!" & SAY
}

[แก้] J

Simplest:

 Hello World

Probably closest in semantics:

'Hello World'

[แก้] Jal

 include 16f877_20
 include hd447804
 
 hd44780_clear
 
 hd44780 = "H"
 hd44780 = "e"
 hd44780 = "l"
 hd44780 = "l"
 hd44780 = "o"
 hd44780 = " "
 hd44780 = "W"
 hd44780 = "o"
 hd44780 = "r"
 hd44780 = "l"
 hd44780 = "d"
 hd44780 = "!"

[แก้] Java

See also GUI section.

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

[แก้] Java byte-code

(disassembler output of javap -c Hello.class)

public class Hello extends java.lang.Object {
    public Hello () ;
    public static void main (java.lang.String[]) ;
}

Method Hello ()
   0 aload_0
   1 invokespecial #1 <Method java.lang.Object () >
   4 return

Method void main (java.lang.String[])
   0 getstatic #2 <Field java.io.PrintStream out>
   3 ldc #3 <String "Hello, world!">
   5 invokevirtual #4 <Method void println (java.lang.String) >
   8 return

[แก้] K

`0:"Hello world\n"

[แก้] Kogut

WriteLine "Hello, world!"

[แก้] Lisp

Lisp has many dialects that have appeared over its almost fifty-year history.

[แก้] Common Lisp

(format t "Hello world!~%")

or

(write-line "Hello World!")

or merely:

 "Hello World!"


[แก้] Scheme

(display "Hello, world!")
(newline)

[แก้] Emacs Lisp

 (print "Hello World")

[แก้] Logo

print [hello  world!]

or

pr [Hello World!]

In mswlogo only

messagebox [Hi] [Hello World]

[แก้] Lua

print "Hello, world!"

[แก้] LuaPSP

screen:print (1,1,"Hello, world!")
screen:flip ()

[แก้] M (MUMPS)

W "Hello, world!"

[แก้] Macsyma, Maxima

print ("Hello, world!") $

[แก้] Maple

print ("Hello, World!") ;

[แก้] Mathematica

Print["Hello World"]

[แก้] MATLAB

disp ('Hello World')

[แก้] Max

max v2;
#N vpatcher 10 59 610 459;
#P message 33 93 63 196617 Hello world!;
#P newex 33 73 45 196617 loadbang;
#P newex 33 111 31 196617 print;
#P connect 1 0 2 0;
#P connect 2 0 0 0;
#P pop;

[แก้] Modula-2

MODULE Hello;

FROM Terminal2 IMPORT WriteLn; WriteString;

BEGIN
   WriteString ("Hello, world!") ;
   WriteLn;
END Hello;

[แก้] MOO

notify (player, "Hello, world!") ;

[แก้] MS-DOS batch

(with the standard command.com interpreter. The @ symbol is optional and prevents the system from repeating the command before executing it. The @ symbol must be omitted on versions of MS-DOS prior to 3.0.)

@echo Hello, world!

[แก้] MUF

: main
  me @ "Hello, world!" notify
;

[แก้] Natural

WRITE "Hello, World!"
END

[แก้] Nemerle

The easiest way to get Nemerle print "Hello, world!" would be that:

System.Console.WriteLine ("Hello, world!") ;

however, in bigger applications the following code would be probably more useful:

using System.Console;

module HelloWorld
{
   Main () :void
   {
      WriteLine ("Hello, world!") ;
   }
}


[แก้] Oberon

Oberon is both the name of a programming language and an operating system.

Program written for the Oberon operating system:

MODULE Hello;
        IMPORT Oberon, Texts;
 VAR W: Texts.Writer;

 PROCEDURE World*;
 BEGIN
   Texts.WriteString (W, "Hello World!") ;
   Texts.WriteLn (W) ;
   Texts.Append (Oberon.Log, W.buf)
 END World;

BEGIN
 Texts.OpenWriter (W)
END Hello.

Freestanding Oberon program using the standard Oakwood library:

MODULE Hello;
   IMPORT Out;
BEGIN
   Out.String ("Hello World!") ;
   Out.Ln
END Hello.

[แก้] Objective C

[