Dragon/Lessons/HelloWorld

From Wikibooks, open books for an open world
Jump to navigation Jump to search


Hello World[edit]

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

	show "Hello World"



Run the program[edit]

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 -f hello.dgn


Multi-Line literals[edit]

Using Dragon we can write multi-line literal, see the next example

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

	    "

you can write showln to print output on new line.

	showln "Hello"
        show "hi"



Getting Input[edit]

You can get the input from the user using the give command

        select "graphic"
        
	a = prompt("What is your name?")
	show "Hello " + a



No Explicit End For Statements[edit]

You don't need to use ';' or press ENTER to separate statements. The previous program can be written in one line.

        select "graphic"

	a = prompt("What is your name?")  show "Hello " + a



Writing Comments[edit]

We can write one line comments and multi-lines comments

The comment starts with //

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

        select "graphic"
                                
	a = prompt("What is your name?")			// print message on screen and get input from the user
	show "Hello " + a		// say hello!

	// show "Bye!"


.. note:: Using // to comment a lines of code is just a code style.