An Introduction to Dragon/Lessons/HelloWorld

Hello World


The following program prints the "Hello World" message on the screen (std-out).

	show "Hello World"

Run the program


To run the program, save the code in a file (for example: hello.dgn), then from the command line or terminal, run it using the Dragon Interpreter:

	dragon -r hello.dgn

Multi-Line literals


Using Dragon we can write multi-line literals, as in this example:

	show "
		Welcome to the Dragon programming language
		How are you?


You can write showln to append a newline to the output:

	showln "Hello"
	show "hi"

Getting Input


You can get input from the user using the readln() method:

	select "std"
	showln "Enter your name" 
	a = readln()
	show "Hello " + a

No Explicit End For Statements


You don't need to use ';' or ENTER to separate statements. Some lines in the previous program that were separate can be combined on one line:

	select "std"
	showln "Enter your name"
	a = readln()  show "Hello " + a

Writing Comments


We can write single-line comments and multi-line comments.

The single-line comment starts with //

Multi-line comments are written between /* and */

	select "std"
	showln "Enter your age"                         
	a = readln()           // print message on screen and get input from the user
	show "Age: " + a       // say hello!
	// show "Bye!"