Computer Programming/Hello world

A Wikibookian believes this page should be split into smaller pages with a narrower subtopic.

You can help by splitting this big page into smaller ones. Please make sure to follow the naming policy. Dividing books into smaller sections can provide more focus and allow each one to do one thing well, which benefits everyone.

Hello, world! programs make the text "Hello, world!" appear on a computer screen. It is usually the first program encountered when learning a programming language. Otherwise, it's a basic sanity check for an installation of a new programming language. If "Hello World" won't run, one must not try to develop complex programs before fixing the issues with the installation.

The Del on the first line begins function definition for the program named HWΔPGM. It is a niladic function (no parameters, as opposed to monadic or dyadic) and it will return an explicit result which allows other functions or APL primitives to use the returned value as input.

The line labeled 1 assigns the text vector 'Hello, world!!' to the variable R

The last line is another Del which ends the function definition.

When the function is executed by typing its name the APL interpreter assigns the text vector to the variable R, but since we have not used this value in another function, primitive, or assignment statement the interpreter returns it to the terminal, thus displaying the words on the next line below the function invocation.

The session would look like this

HWΔPGM
Hello, world!!

While not a program, if you simply supplied the text vector to the interpreter but did not assign it to a variable it would return it to the terminal as output. Note that user input is automatically indented 6 spaces by the interpreter while results are displayed at the beginning of a new line.

10ORG#8000; Start address of the routine20STARTLDA,2; set the output channel30CALL#1601; to channel 2 (main part of TV display)40LDHL,MSG; Set HL register pair to address of the message50LOOPLDA,(HL); De-reference HL and store in A60CP0; Null terminator?70RETZ; If so, return80RST#10; Print the character in A90INCHL; HL points at the next char to be printed100JRLOOP110MSGDEFM"Hello, world!"120DEFB13; carriage return130DEFB0; null terminator

Using FASM import macro, unicode (MessageBoxW is one of few unicode functions 'supported' by Windows 9x/ME) and section sharing, no relocation (not required for 32-bit Windows NT executables, recommended for DOS-based Windows, required for x64), no heap - Not a beginners example but only 1024 instead of 3072 bytes:

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

HELLO CSECT The name of this program is 'HELLO'
USING *,12 Tell assembler what register we are using
SAVE (14,12) Save registers
LR 12,15 Use Register 12 for this program
WTO 'Hello, world!' Write To Operator
RETURN (14,12) Return to calling party
END HELLO This is the end of the program

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):

10PRINT"Hello, world!"20END

Note that the "END" statement is optional in many implementations of BASIC.

Some implementations 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.

In addition to the ANSI syntax at the head of this article, most Pick operating system flavors of Dartmouth BASIC support extended syntax allowing cursor placement and other terminfo type functions for VDT's

X, Y positioning (colon ":" is the concatenation instruction):

PRINT @(34,12) : "Hello, world!"

Will display the string "Hello, world!" roughly centered in a 80X24 CRT.

Other functions:

PRINT @(-1) : @(34,12) : "Hello, world!"

Will clear the screen before displaying the string "Hello, world!" roughly centered in a 80X24 CRT.

Some Pick operating system environments such as OpenQM support the DISPLAY variant of PRINT. This variant in addition to the "@" functions maintains pagination based upon the settings of the TERM variable:

CoffeeScript is a little language that compiles into JavaScript. And like JavaScript, it does not have native (built in) input or output routines. Instead it relies on the facilities provided by its host environment.

Using an alert, using a standard Web browser's window object (window.alert)

(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.). It's very common for batchfiles to start with two lines of "@echo off" and "cls".

; Should work with any MARS >= ICWS-86; with 128x64 gfx coreStartMOV0,2455MOV0,2458MOV0,2459MOV0,2459MOV0,2459MOV0,2459MOV0,2459MOV0,2460MOV0,2465MOV0,2471MOV0,2471MOV0,2471MOV0,2479MOV0,2482MOV0,2484MOV0,2484MOV0,2484MOV0,2486MOV0,2486MOV0,2486MOV0,2486MOV0,2488MOV0,2493MOV0,2493MOV0,2493MOV0,2493MOV0,2497MOV0,2556MOV0,2559MOV0,2560MOV0,2565MOV0,2570MOV0,2575MOV0,2578MOV0,2585MOV0,2588MOV0,2589MOV0,2592MOV0,2593MOV0,2596MOV0,2597MOV0,2603MOV0,2605MOV0,2608MOV0,2667MOV0,2670MOV0,2671MOV0,2676MOV0,2681MOV0,2686MOV0,2689MOV0,2696MOV0,2699MOV0,2700MOV0,2703MOV0,2704MOV0,2707MOV0,2708MOV0,2714MOV0,2716MOV0,2719MOV0,2778MOV0,2778MOV0,2778MOV0,2778MOV0,2778MOV0,2779MOV0,2779MOV0,2779MOV0,2782MOV0,2787MOV0,2792MOV0,2795MOV0,2802MOV0,2805MOV0,2806MOV0,2809MOV0,2810MOV0,2810MOV0,2810MOV0,2810MOV0,2812MOV0,2818MOV0,2820MOV0,2823MOV0,2882MOV0,2885MOV0,2886MOV0,2891MOV0,2896MOV0,2901MOV0,2904MOV0,2911MOV0,2912MOV0,2913MOV0,2914MOV0,2917MOV0,2918MOV0,2919MOV0,2922MOV0,2928MOV0,2930MOV0,2933MOV0,2992MOV0,2995MOV0,2996MOV0,3001MOV0,3006MOV0,3011MOV0,3014MOV0,3021MOV0,3022MOV0,3023MOV0,3024MOV0,3027MOV0,3028MOV0,3030MOV0,3032MOV0,3038MOV0,3040MOV0,3103MOV0,3106MOV0,3107MOV0,3107MOV0,3107MOV0,3107MOV0,3107MOV0,3108MOV0,3108MOV0,3108MOV0,3108MOV0,3108MOV0,3109MOV0,3109MOV0,3109MOV0,3109MOV0,3109MOV0,3111MOV0,3111MOV0,3111MOV0,3120MOV0,3121MOV0,3124MOV0,3124MOV0,3124MOV0,3126MOV0,3129MOV0,3130MOV0,3130MOV0,3130MOV0,3130MOV0,3130MOV0,3131MOV0,3131MOV0,3131MOV0,3131MOV0,3135JMP0

#import <Cocoa/Cocoa.h>@interfacehello : NSObject{}@end@implementationhello-(void)awakeFromNib{NSBeep();// we don't need this but it's conventional to beep // when you show an alertNSRunAlertPanel(@"Message from your Computer",@"Hello, world!",@"Hi!",nil,nil);}@end

#include<QApplication>#include<QPushButton>#include<QVBoxLayout>intmain(intargc,char*argv[]){QApplicationapp(argc,argv);QWidget*window=newQWidget;QVBoxLayout*layout=newQVBoxLayout(window);QPushButton*hello=newQPushButton("Hello, world!",window);//connect the button to quittinghello->connect(hello,SIGNAL(clicked()),&app,SLOT(quit()));layout->addWidget(hello);layout->setMargin(10);layout->setSpacing(10);window->show();returnapp.exec();}

Note that the previous example will only work when the code is entered as part of a Form Load Event, such as the one created by default when generating a new project in the Visual Studio programming environment. Equivalently, the following code is roughly equivalent to the traditional Visual Basic 6 code by disabling the Application Framework and setting 'Sub Main' as the entry point for the application:

The Infamous Hello World Program.
Romeo, a young man with a remarkable patience.
Juliet, a likewise young woman of remarkable grace.
Ophelia, a remarkable woman much in dispute with Hamlet.
Hamlet, the flatterer of Andersen Insulting A/S.
Act I: Hamlet's insults and flattery.
Scene I: The insulting of Romeo.
[Enter Hamlet and Romeo]
Hamlet:
You lying stupid fatherless big smelly half-witted coward!
You are as stupid as the difference between a handsome rich brave
hero and thyself! Speak your mind!
You are as brave as the sum of your fat little stuffed misused dusty
old rotten codpiece and a beautiful fair warm peaceful sunny summer's
day. You are as healthy as the difference between the sum of the
sweetest reddest rose and my father and yourself! Speak your mind!
You are as cowardly as the sum of yourself and the difference
between a big mighty proud kingdom and a horse. Speak your mind.
Speak your mind!
[Exit Romeo]
Scene II: The praising of Juliet.
[Enter Juliet]
Hamlet:
Thou art as sweet as the sum of the sum of Romeo and his horse and his
black cat! Speak thy mind!
[Exit Juliet]
Scene III: The praising of Ophelia.
[Enter Ophelia]
Hamlet:
Thou art as lovely as the product of a large rural town and my amazing
bottomless embroidered purse. Speak thy mind!
Thou art as loving as the product of the bluest clearest sweetest sky
and the sum of a squirrel and a white horse. Thou art as beautiful as
the difference between Juliet and thyself. Speak thy mind!
[Exeunt Ophelia and Hamlet]
Act II: Behind Hamlet's back.
Scene I: Romeo and Juliet's conversation.
[Enter Romeo and Juliet]
Romeo:
Speak your mind. You are as worried as the sum of yourself and the
difference between my small smooth hamster and my nose. Speak your
mind!
Juliet:
Speak YOUR mind! You are as bad as Hamlet! You are as small as the
difference between the square of the difference between my little pony
and your big hairy hound and the cube of your sorry little
codpiece. Speak your mind!
[Exit Romeo]
Scene II: Juliet and Ophelia's conversation.
[Enter Ophelia]
Juliet:
Thou art as good as the quotient between Romeo and the sum of a small
furry animal and a leech. Speak your mind!
Ophelia:
Thou art as disgusting as the quotient between Romeo and twice the
difference between a mistletoe and an oozing infected blister! Speak
your mind!
[Exeunt]