SlideShare a Scribd company logo
Ring Documentation, Release 1.10
Example:
Put "
Main Menu
---------
(1) Say Hello
(2) About
(3) Exit
" Get nOption
Switch nOption
Case 1 Put "Enter your name : " Get name Put "Hello " + name + nl
Case 2 Put "Sample : using switch statement" + nl
Case 3 Bye
Else Put "bad option..." + nl
End
24.2 Looping
• While Loop
Syntax:
while Expression
Block of statements
end
Example:
While True
Put "
Main Menu
---------
(1) Say Hello
(2) About
(3) Exit
" Get nOption
Switch nOption
Case 1
Put "Enter your name : "
Get name
Put "Hello " + name + nl
Case 2
Put "Sample : using while loop" + nl
Case 3
Bye
Else
Put "bad option..." + nl
End
End
• For Loop
Syntax:
24.2. Looping 238
Ring Documentation, Release 1.10
for identifier=expression to expression [step expression]
Block of statements
end
Example:
# print numbers from 1 to 10
for x = 1 to 10 put x + nl end
Example:
# Dynamic loop
Put "Start : " get nStart
Put "End : " get nEnd
Put "Step : " get nStep
For x = nStart to nEnd Step nStep
Put x + nl
End
Example:
# print even numbers from 0 to 10
for x = 0 to 10 step 2
Put x + nl
end
Example:
# print even numbers from 10 to 0
for x = 10 to 0 step -2
put x + nl
end
• For in Loop
Syntax:
for identifier in List/String [step expression]
Block of statements
end
Example:
aList = 1:10 # create list contains numbers from 1 to 10
for x in aList put x + nl end # print numbers from 1 to 10
24.3 Exceptions
try
Block of statements
catch
Block of statements
end
24.3. Exceptions 239
CHAPTER
TWENTYFIVE
CONTROL STRUCTURES - THIRD STYLE
In this chapter we are going to learn about the third style of control structures provided by the Ring programming
language.
25.1 Branching
• If Statement
Syntax:
if Expression {
Block of statements
elseif Expression
Block of statements
else
Block of statements
}
Example:
Load "stdlib.ring"
print("
Main Menu
---------
(1) Say Hello
(2) About
(3) Exit
")
nOption = getnumber()
if nOption = 1 {
print("Enter your name : ")
name = getstring()
print("Hello #{name}n")
elseif nOption = 2
print("Sample : using if statementn")
elseif nOption = 3
bye
else
print("bad option...n")
}
240
Ring Documentation, Release 1.10
• Switch Statement
Syntax:
switch Expression {
case Expression
Block of statements
else
Block of statements
}
Example:
Load "stdlib.ring"
print("
Main Menu
---------
(1) Say Hello
(2) About
(3) Exit
")
nOption = GetString()
switch nOption {
case 1
print("Enter your name : ")
name = getstring()
print("Hello #{name}n")
case 2
print("Sample : using switch statementn")
case 3
Bye
else
print("bad option...n")
}
25.2 Looping
• While Loop
Syntax:
while Expression {
Block of statements
}
Example:
Load "stdlib.ring"
While True {
print("
Main Menu
---------
25.2. Looping 241
Ring Documentation, Release 1.10
(1) Say Hello
(2) About
(3) Exit
")
nOption = GetString()
switch nOption {
case 1
print("Enter your name : ")
name = getstring()
print("Hello #{name}n")
case 2
print("Sample : using switch statementn")
case 3
Bye
else
print("bad option...n")
}
}
• For Loop
Syntax:
for identifier=expression to expression [step expression] {
Block of statements
}
Example:
# print numbers from 1 to 10
load "stdlib.ring"
for x = 1 to 10 {
print("#{x}n")
}
Example:
load "stdlib.ring"
# Dynamic loop
print("Start : ") nStart = getnumber()
print("End : ") nEnd = getnumber()
print("Step : ") nStep = getnumber()
for x = nStart to nEnd step nStep {
print("#{x}n")
}
Example:
load "stdlib.ring"
# print even numbers from 0 to 10
for x = 0 to 10 step 2 {
print("#{x}n")
}
25.2. Looping 242
Ring Documentation, Release 1.10
Example:
load "stdlib.ring"
# print even numbers from 10 to 0
for x = 10 to 0 step -2 {
print("#{x}n")
}
• For in Loop
Syntax:
for identifier in List/String [step expression] {
Block of statements
}
Example:
load "stdlib.ring"
aList = 1:10 # create list contains numbers from 1 to 10
for x in aList { print("#{x}n") } # print numbers from 1 to 10
Example:
load "stdlib.ring"
aList = 1:10 # create list contains numbers from 1 to 10
# print odd items inside the list
for x in aList step 2 {
print("#{x}n")
}
When we use (For in) we get items by reference.
This means that we can read/edit items inside the loop.
Example:
load "stdlib.ring"
aList = 1:5 # create list contains numbers from 1 to 5
# replace list numbers with strings
for x in aList {
switch x {
case 1 x = "one"
case 2 x = "two"
case 3 x = "three"
case 4 x = "four"
case 5 x = "five"
}
}
print(aList) # print the list items
25.3 Exceptions
25.3. Exceptions 243
Ring Documentation, Release 1.10
try {
Block of statements
catch
Block of statements
}
25.3. Exceptions 244
CHAPTER
TWENTYSIX
GETTING INPUT
We can get input from the keyboard using
• The Give Command
• The GetChar() Function
• The Input() Function
26.1 Give Command
Syntax:
Give VariableName
Example:
See "Enter the first number : " Give nNum1
See "Enter the second number : " Give nNum2
See "Sum : " + ( 0 + nNum1 + nNum2 )
Output:
Enter the first number : 3
Enter the second number : 4
Sum : 7
26.2 GetChar() Function
We can get one character from the standard input using the GetChar() function
Syntax:
GetChar() ---> Character
Example:
While True
See "
Main Menu
(1) Say Hello
(2) Exit
"
Option = GetChar()
245
Ring Documentation, Release 1.10
GetChar() GetChar() # End of line
# the previous two lines can be replaced with the next line
# Give Option
if Option = 1
see "Enter your name : " give cName
see "Hello " + cName
else
bye
ok
End
26.3 Input() Function
We can get input from the keyboard using the Input() function
Syntax:
Input(nCount) ---> string
The function will wait until nCount characters (at least) are read
Example:
See "Enter message (30 characters) : " cMsg = input(30)
See "Message : " + cMsg
26.3. Input() Function 246
CHAPTER
TWENTYSEVEN
FUNCTIONS - FIRST STYLE
In this chapter we are going to learn about the next topics :-
• Define functions
• Call functions
• Declare parameters
• Send parameters
• Main Function
• Variables Scope
• Return Value
• Recursion
27.1 Define Functions
To define new function
Syntax:
func <function_name> [parameters]
Block of statements
Note: No keyword is required to end the function definition.
Example:
func hello
see "Hello from function" + nl
27.2 Call Functions
To call function without parameters, we type the function name then ()
Tip: We can call the function before the function definition and the function code.
Example:
247

More Related Content

PDF
The Ring programming language version 1.6 book - Part 22 of 189
PDF
The Ring programming language version 1.5.3 book - Part 20 of 184
PDF
The Ring programming language version 1.7 book - Part 23 of 196
PDF
The Ring programming language version 1.4 book - Part 5 of 30
PDF
The Ring programming language version 1.3 book - Part 12 of 88
PDF
The Ring programming language version 1.5.2 book - Part 19 of 181
PDF
The Ring programming language version 1.5.4 book - Part 20 of 185
PDF
The Ring programming language version 1.4.1 book - Part 5 of 31
The Ring programming language version 1.6 book - Part 22 of 189
The Ring programming language version 1.5.3 book - Part 20 of 184
The Ring programming language version 1.7 book - Part 23 of 196
The Ring programming language version 1.4 book - Part 5 of 30
The Ring programming language version 1.3 book - Part 12 of 88
The Ring programming language version 1.5.2 book - Part 19 of 181
The Ring programming language version 1.5.4 book - Part 20 of 185
The Ring programming language version 1.4.1 book - Part 5 of 31

What's hot (20)

PDF
The Ring programming language version 1.9 book - Part 27 of 210
PDF
The Ring programming language version 1.2 book - Part 10 of 84
PDF
The Ring programming language version 1.2 book - Part 13 of 84
PDF
The Ring programming language version 1.2 book - Part 12 of 84
PDF
The Ring programming language version 1.2 book - Part 9 of 84
PDF
The Ring programming language version 1.2 book - Part 11 of 84
PDF
The Ring programming language version 1.8 book - Part 25 of 202
PDF
The Ring programming language version 1.3 book - Part 18 of 88
PDF
The Ring programming language version 1.10 book - Part 31 of 212
PDF
The Ring programming language version 1.5.4 book - Part 27 of 185
PDF
The Ring programming language version 1.9 book - Part 34 of 210
PDF
The Ring programming language version 1.5.4 book - Part 23 of 185
PDF
Pivorak Clojure by Dmytro Bignyak
PDF
The Ring programming language version 1.6 book - Part 183 of 189
PDF
Generics and Inference
PDF
The Ring programming language version 1.3 book - Part 32 of 88
PPTX
Linked list without animation
PDF
The Ring programming language version 1.5.4 book - Part 24 of 185
PDF
The Ring programming language version 1.5.4 book - Part 25 of 185
PDF
Are we ready to Go?
The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 13 of 84
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.8 book - Part 25 of 202
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.10 book - Part 31 of 212
The Ring programming language version 1.5.4 book - Part 27 of 185
The Ring programming language version 1.9 book - Part 34 of 210
The Ring programming language version 1.5.4 book - Part 23 of 185
Pivorak Clojure by Dmytro Bignyak
The Ring programming language version 1.6 book - Part 183 of 189
Generics and Inference
The Ring programming language version 1.3 book - Part 32 of 88
Linked list without animation
The Ring programming language version 1.5.4 book - Part 24 of 185
The Ring programming language version 1.5.4 book - Part 25 of 185
Are we ready to Go?
Ad

Similar to The Ring programming language version 1.10 book - Part 28 of 212 (20)

PDF
The Ring programming language version 1.8 book - Part 24 of 202
PDF
The Ring programming language version 1.9 book - Part 26 of 210
PDF
The Ring programming language version 1.5.1 book - Part 18 of 180
PDF
The Ring programming language version 1.5.2 book - Part 26 of 181
PDF
The Ring programming language version 1.5.1 book - Part 19 of 180
PDF
The Ring programming language version 1.9 book - Part 31 of 210
PDF
The Ring programming language version 1.8 book - Part 29 of 202
PDF
The Ring programming language version 1.3 book - Part 14 of 88
PDF
The Ring programming language version 1.4 book - Part 29 of 30
PDF
The Ring programming language version 1.9 book - Part 32 of 210
PDF
The Ring programming language version 1.8 book - Part 94 of 202
PDF
The Ring programming language version 1.5.2 book - Part 175 of 181
PDF
The Ring programming language version 1.4 book - Part 6 of 30
PDF
The Ring programming language version 1.6 book - Part 26 of 189
PDF
The Ring programming language version 1.5.4 book - Part 179 of 185
PDF
The Ring programming language version 1.3 book - Part 13 of 88
PDF
The Ring programming language version 1.5.2 book - Part 24 of 181
PDF
The Ring programming language version 1.2 book - Part 16 of 84
PDF
The Ring programming language version 1.7 book - Part 26 of 196
PDF
The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.8 book - Part 24 of 202
The Ring programming language version 1.9 book - Part 26 of 210
The Ring programming language version 1.5.1 book - Part 18 of 180
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.4 book - Part 29 of 30
The Ring programming language version 1.9 book - Part 32 of 210
The Ring programming language version 1.8 book - Part 94 of 202
The Ring programming language version 1.5.2 book - Part 175 of 181
The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.6 book - Part 26 of 189
The Ring programming language version 1.5.4 book - Part 179 of 185
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.2 book - Part 16 of 84
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.5 book - Part 3 of 31
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
PDF
The Ring programming language version 1.10 book - Part 211 of 212
PDF
The Ring programming language version 1.10 book - Part 210 of 212
PDF
The Ring programming language version 1.10 book - Part 208 of 212
PDF
The Ring programming language version 1.10 book - Part 207 of 212
PDF
The Ring programming language version 1.10 book - Part 205 of 212
PDF
The Ring programming language version 1.10 book - Part 206 of 212
PDF
The Ring programming language version 1.10 book - Part 204 of 212
PDF
The Ring programming language version 1.10 book - Part 203 of 212
PDF
The Ring programming language version 1.10 book - Part 202 of 212
PDF
The Ring programming language version 1.10 book - Part 201 of 212
PDF
The Ring programming language version 1.10 book - Part 200 of 212
PDF
The Ring programming language version 1.10 book - Part 199 of 212
PDF
The Ring programming language version 1.10 book - Part 198 of 212
PDF
The Ring programming language version 1.10 book - Part 197 of 212
PDF
The Ring programming language version 1.10 book - Part 196 of 212
PDF
The Ring programming language version 1.10 book - Part 195 of 212
PDF
The Ring programming language version 1.10 book - Part 194 of 212
PDF
The Ring programming language version 1.10 book - Part 193 of 212
PDF
The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 211 of 212
The Ring programming language version 1.10 book - Part 210 of 212
The Ring programming language version 1.10 book - Part 208 of 212
The Ring programming language version 1.10 book - Part 207 of 212
The Ring programming language version 1.10 book - Part 205 of 212
The Ring programming language version 1.10 book - Part 206 of 212
The Ring programming language version 1.10 book - Part 204 of 212
The Ring programming language version 1.10 book - Part 203 of 212
The Ring programming language version 1.10 book - Part 202 of 212
The Ring programming language version 1.10 book - Part 201 of 212
The Ring programming language version 1.10 book - Part 200 of 212
The Ring programming language version 1.10 book - Part 199 of 212
The Ring programming language version 1.10 book - Part 198 of 212
The Ring programming language version 1.10 book - Part 197 of 212
The Ring programming language version 1.10 book - Part 196 of 212
The Ring programming language version 1.10 book - Part 195 of 212
The Ring programming language version 1.10 book - Part 194 of 212
The Ring programming language version 1.10 book - Part 193 of 212
The Ring programming language version 1.10 book - Part 192 of 212

Recently uploaded (20)

PPTX
Essential Infomation Tech presentation.pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Introduction to Artificial Intelligence
PDF
System and Network Administraation Chapter 3
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Digital Strategies for Manufacturing Companies
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
medical staffing services at VALiNTRY
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Essential Infomation Tech presentation.pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Introduction to Artificial Intelligence
System and Network Administraation Chapter 3
VVF-Customer-Presentation2025-Ver1.9.pptx
Digital Strategies for Manufacturing Companies
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Upgrade and Innovation Strategies for SAP ERP Customers
Wondershare Filmora 15 Crack With Activation Key [2025
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
medical staffing services at VALiNTRY
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
How Creative Agencies Leverage Project Management Software.pdf
Understanding Forklifts - TECH EHS Solution
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...

The Ring programming language version 1.10 book - Part 28 of 212

  • 1. Ring Documentation, Release 1.10 Example: Put " Main Menu --------- (1) Say Hello (2) About (3) Exit " Get nOption Switch nOption Case 1 Put "Enter your name : " Get name Put "Hello " + name + nl Case 2 Put "Sample : using switch statement" + nl Case 3 Bye Else Put "bad option..." + nl End 24.2 Looping • While Loop Syntax: while Expression Block of statements end Example: While True Put " Main Menu --------- (1) Say Hello (2) About (3) Exit " Get nOption Switch nOption Case 1 Put "Enter your name : " Get name Put "Hello " + name + nl Case 2 Put "Sample : using while loop" + nl Case 3 Bye Else Put "bad option..." + nl End End • For Loop Syntax: 24.2. Looping 238
  • 2. Ring Documentation, Release 1.10 for identifier=expression to expression [step expression] Block of statements end Example: # print numbers from 1 to 10 for x = 1 to 10 put x + nl end Example: # Dynamic loop Put "Start : " get nStart Put "End : " get nEnd Put "Step : " get nStep For x = nStart to nEnd Step nStep Put x + nl End Example: # print even numbers from 0 to 10 for x = 0 to 10 step 2 Put x + nl end Example: # print even numbers from 10 to 0 for x = 10 to 0 step -2 put x + nl end • For in Loop Syntax: for identifier in List/String [step expression] Block of statements end Example: aList = 1:10 # create list contains numbers from 1 to 10 for x in aList put x + nl end # print numbers from 1 to 10 24.3 Exceptions try Block of statements catch Block of statements end 24.3. Exceptions 239
  • 3. CHAPTER TWENTYFIVE CONTROL STRUCTURES - THIRD STYLE In this chapter we are going to learn about the third style of control structures provided by the Ring programming language. 25.1 Branching • If Statement Syntax: if Expression { Block of statements elseif Expression Block of statements else Block of statements } Example: Load "stdlib.ring" print(" Main Menu --------- (1) Say Hello (2) About (3) Exit ") nOption = getnumber() if nOption = 1 { print("Enter your name : ") name = getstring() print("Hello #{name}n") elseif nOption = 2 print("Sample : using if statementn") elseif nOption = 3 bye else print("bad option...n") } 240
  • 4. Ring Documentation, Release 1.10 • Switch Statement Syntax: switch Expression { case Expression Block of statements else Block of statements } Example: Load "stdlib.ring" print(" Main Menu --------- (1) Say Hello (2) About (3) Exit ") nOption = GetString() switch nOption { case 1 print("Enter your name : ") name = getstring() print("Hello #{name}n") case 2 print("Sample : using switch statementn") case 3 Bye else print("bad option...n") } 25.2 Looping • While Loop Syntax: while Expression { Block of statements } Example: Load "stdlib.ring" While True { print(" Main Menu --------- 25.2. Looping 241
  • 5. Ring Documentation, Release 1.10 (1) Say Hello (2) About (3) Exit ") nOption = GetString() switch nOption { case 1 print("Enter your name : ") name = getstring() print("Hello #{name}n") case 2 print("Sample : using switch statementn") case 3 Bye else print("bad option...n") } } • For Loop Syntax: for identifier=expression to expression [step expression] { Block of statements } Example: # print numbers from 1 to 10 load "stdlib.ring" for x = 1 to 10 { print("#{x}n") } Example: load "stdlib.ring" # Dynamic loop print("Start : ") nStart = getnumber() print("End : ") nEnd = getnumber() print("Step : ") nStep = getnumber() for x = nStart to nEnd step nStep { print("#{x}n") } Example: load "stdlib.ring" # print even numbers from 0 to 10 for x = 0 to 10 step 2 { print("#{x}n") } 25.2. Looping 242
  • 6. Ring Documentation, Release 1.10 Example: load "stdlib.ring" # print even numbers from 10 to 0 for x = 10 to 0 step -2 { print("#{x}n") } • For in Loop Syntax: for identifier in List/String [step expression] { Block of statements } Example: load "stdlib.ring" aList = 1:10 # create list contains numbers from 1 to 10 for x in aList { print("#{x}n") } # print numbers from 1 to 10 Example: load "stdlib.ring" aList = 1:10 # create list contains numbers from 1 to 10 # print odd items inside the list for x in aList step 2 { print("#{x}n") } When we use (For in) we get items by reference. This means that we can read/edit items inside the loop. Example: load "stdlib.ring" aList = 1:5 # create list contains numbers from 1 to 5 # replace list numbers with strings for x in aList { switch x { case 1 x = "one" case 2 x = "two" case 3 x = "three" case 4 x = "four" case 5 x = "five" } } print(aList) # print the list items 25.3 Exceptions 25.3. Exceptions 243
  • 7. Ring Documentation, Release 1.10 try { Block of statements catch Block of statements } 25.3. Exceptions 244
  • 8. CHAPTER TWENTYSIX GETTING INPUT We can get input from the keyboard using • The Give Command • The GetChar() Function • The Input() Function 26.1 Give Command Syntax: Give VariableName Example: See "Enter the first number : " Give nNum1 See "Enter the second number : " Give nNum2 See "Sum : " + ( 0 + nNum1 + nNum2 ) Output: Enter the first number : 3 Enter the second number : 4 Sum : 7 26.2 GetChar() Function We can get one character from the standard input using the GetChar() function Syntax: GetChar() ---> Character Example: While True See " Main Menu (1) Say Hello (2) Exit " Option = GetChar() 245
  • 9. Ring Documentation, Release 1.10 GetChar() GetChar() # End of line # the previous two lines can be replaced with the next line # Give Option if Option = 1 see "Enter your name : " give cName see "Hello " + cName else bye ok End 26.3 Input() Function We can get input from the keyboard using the Input() function Syntax: Input(nCount) ---> string The function will wait until nCount characters (at least) are read Example: See "Enter message (30 characters) : " cMsg = input(30) See "Message : " + cMsg 26.3. Input() Function 246
  • 10. CHAPTER TWENTYSEVEN FUNCTIONS - FIRST STYLE In this chapter we are going to learn about the next topics :- • Define functions • Call functions • Declare parameters • Send parameters • Main Function • Variables Scope • Return Value • Recursion 27.1 Define Functions To define new function Syntax: func <function_name> [parameters] Block of statements Note: No keyword is required to end the function definition. Example: func hello see "Hello from function" + nl 27.2 Call Functions To call function without parameters, we type the function name then () Tip: We can call the function before the function definition and the function code. Example: 247