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

Hello World[edit | edit source]

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

	see "Hello World"

Run the program[edit | edit source]

to run the program, save the code in a file, for example : hello.ring then from the command line or terminal, run it using the ring interpreter

	ring hello.ring

Not Case-Sensitive[edit | edit source]

Since the Ring language is not case-sensitive, the same program can be written in different styles

.. tip:: It's better to select one style and use it in all of the program source code

	SEE "Hello World"
	See "Hello World"

Multi-Line literals[edit | edit source]

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

	See "
		Welcome to the Ring programming language
		How are you?


Also you can use the nl constant to insert new line and you can use the + operator to concatenate strings

.. note:: nl value means a new line and the actual codes that represent a newline is different between operating systems

	See "Hello" + nl + "Welcome to the Ring programming language" + 
	    nl + "How are you?"

Getting Input[edit | edit source]

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

	See "What is your name? "
	Give cName
	See "Hello " + cName

No Explicit End For Statements[edit | edit source]

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

	See "What is your name? " give cName see "Hello " + cName

Writing Comments[edit | edit source]

We can write one line comments and multi-lines comments

The comment starts with # or //

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

		Program Name : My first program using Ring
		Date         : 2015.05.08
		Author       : Mahmoud Fayed

	See "What is your name? " 	# print message on screen
	give cName 			# get input from the user
	see "Hello " + cName		# say hello!

	// See "Bye!"

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