< Dragon < Lessons
Hello World
The next 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 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
You can get the 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 press ENTER to separate statements.
The previous program can be written in one line.
select "std"
showln "Enter your name"
a = readln() show "Hello " + a
Writing Comments
We can write one line comments and multi-lines comments
The comment starts with //
Multi-lines 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!"
.. note:: Using // to comment a lines of code is just a code style.
This article is issued from
Wikibooks.
The text is licensed under Creative
Commons - Attribution - Sharealike.
Additional terms may apply for the media files.