Professional Resume Template for Software Developers
The Ring programming language version 1.9 book - Part 23 of 210
1. CHAPTER
SIXTEEN
GETTING STARTED - SECOND STYLE
16.1 Hello World
The next program prints the Hello World message on the screen (std-out).
put "Hello World"
16.2 Run the program
to run the program, save the code in a file, for example : hello.ring then from the command line or terminal, run it
using Ring
ring hello.ring
16.3 Create Executable File
Using Ring2EXE we can create executable file for our application
ring2exe hello.ring -static
16.4 Not Case-Sensitive
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
PUT "Hello World"
Put "Hello World"
16.5 Multi-Line literals
Using Ring we can write multi-line literal, see the next example
189
2. Ring Documentation, Release 1.9
Put "
Hello
Welcome to the Ring programming language
How are you?
"
Also you can use the nl variable to insert new line and you can use the + operator to concatenate strings
As we have NL for new lines, we have Tab and CR (Carriage return) too!
Note: nl value means a new line and the actual codes that represent a newline is different between operating systems
Put "Hello" + nl + "Welcome to the Ring programming language" +
nl + "How are you?"
16.6 Getting Input
You can get the input from the user using the get command
Put "What is your name? "
Get cName
Put "Hello " + cName
16.7 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.
Put "What is your name? " get cName put "Hello " + cName
16.8 Writing Comments
We can write one line comments and multi-line comments
The comment starts with # or //
Multi-lines comments are written between /* and */
/*
Program Name : My first program using Ring
Date : 2016.09.09
Author : Mahmoud Fayed
*/
Put "What is your name? " # print message on screen
get cName # get input from the user
put "Hello " + cName # say hello!
// Put "Bye!"
Note: Using // to comment a lines of code is just a code style.
16.6. Getting Input 190
3. CHAPTER
SEVENTEEN
GETTING STARTED - THIRD STYLE
17.1 Hello World
The next program prints the Hello World message on the screen (std-out).
load "stdlib.ring"
print("Hello World")
17.2 Run the program
to run the program, save the code in a file, for example : hello.ring then from the command line or terminal, run it
using Ring
ring hello.ring
17.3 Create Executable File
Using Ring2EXE we can create executable file for our application
ring2exe hello.ring -static
The -static option will avoid the need to ring.dll|ring.so|ring.dylib
But since the stdlib.ring load libraries like (LibCurl, OpenSSL, MySQL, etc)
You will need these libraries!
To avoid the need to these libraries (If you don’t need stdlib classes)
Use stdlibcore.ring instead of stdlib.ring as in the next example
load "stdlibcore.ring"
print("Hello World")
Using stdlibcore.ring You can access the stdlib functions but not the stdlib classes.
if you want to use stdlib.ring and distribute your application
ring2exe hello.ring -dist -allruntime -noqt -noallegro
191
4. Ring Documentation, Release 1.9
17.4 Not Case-Sensitive
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
LOAD "stdlib.ring"
PRINT("Hello World")
Load "stdlib.ring"
Print("Hello World")
17.5 Multi-Line literals
Using Ring we can write multi-line literal, see the next example
Load "stdlib.ring"
Print("
Hello
Welcome to the Ring programming language
How are you?
")
Also you can use the n to insert new line and you can use #{variable_name} to insert variables values.
Load "stdlib.ring"
Print( "HellonWelcome to the Ring programming languagenHow are you?")
17.6 Getting Input
You can get the input from the user using the getstring() function
Load "stdlib.ring"
Print("What is your name? ")
cName = GetString()
Print("Hello #{cName}")
17.7 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.
Load "stdlib.ring"
Print("What is your name? ") cName=getstring() print("Hello #{cName}")
17.8 Writing Comments
We can write one line comments and multi-line comments
17.4. Not Case-Sensitive 192
5. Ring Documentation, Release 1.9
The comment starts with # or //
Multi-lines comments are written between /* and */
/*
Program Name : My first program using Ring
Date : 2016.09.09
Author : Mahmoud Fayed
*/
Load "stdlib.ring"
Print("What is your name? ") # print message on screen
cName=GetString() # get input from the user
print("Hello #{cName}") # say hello!
// print("Bye!")
Note: Using // to comment a lines of code is just a code style.
17.8. Writing Comments 193
6. CHAPTER
EIGHTEEN
USING RING NOTEPAD
In this chapter we will learn about using Ring Notepad to write and execute Ring programs quickly
Ring Notepad is just a simple application developed using the Ring language.
18.1 Ring Notepad - Main Window
When we run the Ring Notepad we get the next dockable windows
• Project Files Window : where we can select and open any ring file (*.ring) quickly.
• Source Code Window : Where we write the source code.
• Form Designer Window : The Form Designer to create GUI application forms.
• Web Browser Window : Where we read the documentation or quickly open any website.
• Output Window : Output when we run programs that print to the standard output
• Function Window : List of functions in the current source file
• Classes Window : List of classes in the current source file
194
7. Ring Documentation, Release 1.9
18.2 Creating and running your first Console Application
At first we will type the source code
See "Hello, World!"
As in the next image
Then we will click on the “Save” button from the toolbar (or press CTRL+S)
Determine the source code file name and location.
For example type : hello
This will create a new source code file called : hello.ring
18.2. Creating and running your first Console Application 195
8. Ring Documentation, Release 1.9
To run the program click on “Debug (Run then wait!)” button from the toolbar
The next screen shot present the application during the runtime
Press Enter to continue and return to the Ring Notepad.
18.2. Creating and running your first Console Application 196
9. Ring Documentation, Release 1.9
18.3 Creating and running your first GUI/Mobile Application
To learn how to create GUI applications using Ring check the “Desktop and Mobile development using RingQt”
chapter.
Source Code:
Load "guilib.ring"
New qApp {
new qWidget() {
resize(400,400)
setWindowTitle("Hello, World!")
show()
}
exec()
}
In Ring notepad we have a special button to run GUI applications without displaying the console window.
18.3. Creating and running your first GUI/Mobile Application 197
10. Ring Documentation, Release 1.9
The next screen shot present the application during the runtime
18.4 Creating and running your first Web Application
To learn how support Ring in your web server and how to create web applications using Ring check the “Web Devel-
opment (CGI Library)” chapter.
Note: You need to support the Ring language in your web server to be able to run the next example.
Source Code:
#!b:ringbinring.exe -cgi
load "weblib.ring"
Import System.Web
new page {
text("Hello, World!")
}
We can run the application in any web browser or in the browser that are embedded in Ring Notepad.
18.4. Creating and running your first Web Application 198