SlideShare a Scribd company logo
1 of 10
Download to read offline
Ring Documentation, Release 1.5.3
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
19.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:
19.2. Looping 165
Ring Documentation, Release 1.5.3
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
19.3 Exceptions
try
Block of statements
catch
Block of statements
end
19.3. Exceptions 166
CHAPTER
TWENTY
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.
20.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")
}
167
Ring Documentation, Release 1.5.3
• 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")
}
20.2 Looping
• While Loop
Syntax:
while Expression {
Block of statements
}
Example:
Load "stdlib.ring"
While True {
print("
Main Menu
---------
20.2. Looping 168
Ring Documentation, Release 1.5.3
(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")
}
20.2. Looping 169
Ring Documentation, Release 1.5.3
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
20.3 Exceptions
20.3. Exceptions 170
Ring Documentation, Release 1.5.3
try {
Block of statements
catch
Block of statements
}
20.3. Exceptions 171
CHAPTER
TWENTYONE
GETTING INPUT
We can get input from the keyboard using
• The Give Command
• The GetChar() Function
• The Input() Function
21.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
21.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()
172
Ring Documentation, Release 1.5.3
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
21.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
21.3. Input() Function 173
CHAPTER
TWENTYTWO
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
22.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
22.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:
174

More Related Content

What's hot

The Ring programming language version 1.9 book - Part 34 of 210
The Ring programming language version 1.9 book - Part 34 of 210The Ring programming language version 1.9 book - Part 34 of 210
The Ring programming language version 1.9 book - Part 34 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 13 of 84
The Ring programming language version 1.2 book - Part 13 of 84The Ring programming language version 1.2 book - Part 13 of 84
The Ring programming language version 1.2 book - Part 13 of 84Mahmoud Samir Fayed
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?Adam Dudczak
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and InferenceRichard Fox
 
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185Mahmoud Samir Fayed
 
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak MeetUp
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my dayTor Ivry
 
RedHat/CentOs Commands for administrative works
RedHat/CentOs Commands for administrative worksRedHat/CentOs Commands for administrative works
RedHat/CentOs Commands for administrative worksMd Shihab
 
The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.3 book - Part 14 of 88The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.3 book - Part 14 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.4 book - Part 7 of 30
The Ring programming language version 1.4 book - Part 7 of 30The Ring programming language version 1.4 book - Part 7 of 30
The Ring programming language version 1.4 book - Part 7 of 30Mahmoud Samir Fayed
 
Introduction to go
Introduction to goIntroduction to go
Introduction to goJaehue Jang
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...ssuserd6b1fd
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - FunctionCody Yun
 

What's hot (20)

The Ring programming language version 1.9 book - Part 34 of 210
The Ring programming language version 1.9 book - Part 34 of 210The Ring programming language version 1.9 book - Part 34 of 210
The Ring programming language version 1.9 book - Part 34 of 210
 
The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189The Ring programming language version 1.6 book - Part 25 of 189
The Ring programming language version 1.6 book - Part 25 of 189
 
The Ring programming language version 1.2 book - Part 13 of 84
The Ring programming language version 1.2 book - Part 13 of 84The Ring programming language version 1.2 book - Part 13 of 84
The Ring programming language version 1.2 book - Part 13 of 84
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
 
The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185The Ring programming language version 1.5.4 book - Part 23 of 185
The Ring programming language version 1.5.4 book - Part 23 of 185
 
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro Bignyak
 
Go ahead, make my day
Go ahead, make my dayGo ahead, make my day
Go ahead, make my day
 
c programming
c programmingc programming
c programming
 
RedHat/CentOs Commands for administrative works
RedHat/CentOs Commands for administrative worksRedHat/CentOs Commands for administrative works
RedHat/CentOs Commands for administrative works
 
The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181
 
c programming
c programmingc programming
c programming
 
The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.3 book - Part 14 of 88The Ring programming language version 1.3 book - Part 14 of 88
The Ring programming language version 1.3 book - Part 14 of 88
 
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210
 
The Ring programming language version 1.4 book - Part 7 of 30
The Ring programming language version 1.4 book - Part 7 of 30The Ring programming language version 1.4 book - Part 7 of 30
The Ring programming language version 1.4 book - Part 7 of 30
 
Introduction to go
Introduction to goIntroduction to go
Introduction to go
 
C++ L04-Array+String
C++ L04-Array+StringC++ L04-Array+String
C++ L04-Array+String
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
Hello Swift 3/5 - Function
Hello Swift 3/5 - FunctionHello Swift 3/5 - Function
Hello Swift 3/5 - Function
 

Similar to The Ring programming language version 1.5.3 book - Part 20 of 184

The Ring programming language version 1.4 book - Part 5 of 30
The Ring programming language version 1.4 book - Part 5 of 30The Ring programming language version 1.4 book - Part 5 of 30
The Ring programming language version 1.4 book - Part 5 of 30Mahmoud Samir Fayed
 
The Ring programming language version 1.4.1 book - Part 5 of 31
The Ring programming language version 1.4.1 book - Part 5 of 31The Ring programming language version 1.4.1 book - Part 5 of 31
The Ring programming language version 1.4.1 book - Part 5 of 31Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 18 of 180
The Ring programming language version 1.5.1 book - Part 18 of 180The Ring programming language version 1.5.1 book - Part 18 of 180
The Ring programming language version 1.5.1 book - Part 18 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 24 of 202
The Ring programming language version 1.8 book - Part 24 of 202The Ring programming language version 1.8 book - Part 24 of 202
The Ring programming language version 1.8 book - Part 24 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.9 book - Part 27 of 210The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.9 book - Part 27 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 26 of 210
The Ring programming language version 1.9 book - Part 26 of 210The Ring programming language version 1.9 book - Part 26 of 210
The Ring programming language version 1.9 book - Part 26 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 25 of 202
The Ring programming language version 1.8 book - Part 25 of 202The Ring programming language version 1.8 book - Part 25 of 202
The Ring programming language version 1.8 book - Part 25 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.5.1 book - Part 19 of 180The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.5.1 book - Part 19 of 180Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 19 of 184
The Ring programming language version 1.5.3 book - Part 19 of 184The Ring programming language version 1.5.3 book - Part 19 of 184
The Ring programming language version 1.5.3 book - Part 19 of 184Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196Mahmoud Samir Fayed
 

Similar to The Ring programming language version 1.5.3 book - Part 20 of 184 (20)

The Ring programming language version 1.4 book - Part 5 of 30
The Ring programming language version 1.4 book - Part 5 of 30The Ring programming language version 1.4 book - Part 5 of 30
The Ring programming language version 1.4 book - Part 5 of 30
 
The Ring programming language version 1.4.1 book - Part 5 of 31
The Ring programming language version 1.4.1 book - Part 5 of 31The Ring programming language version 1.4.1 book - Part 5 of 31
The Ring programming language version 1.4.1 book - Part 5 of 31
 
The Ring programming language version 1.5.1 book - Part 18 of 180
The Ring programming language version 1.5.1 book - Part 18 of 180The Ring programming language version 1.5.1 book - Part 18 of 180
The Ring programming language version 1.5.1 book - Part 18 of 180
 
The Ring programming language version 1.8 book - Part 24 of 202
The Ring programming language version 1.8 book - Part 24 of 202The Ring programming language version 1.8 book - Part 24 of 202
The Ring programming language version 1.8 book - Part 24 of 202
 
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 10 of 84
 
The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.9 book - Part 27 of 210The Ring programming language version 1.9 book - Part 27 of 210
The Ring programming language version 1.9 book - Part 27 of 210
 
The Ring programming language version 1.9 book - Part 26 of 210
The Ring programming language version 1.9 book - Part 26 of 210The Ring programming language version 1.9 book - Part 26 of 210
The Ring programming language version 1.9 book - Part 26 of 210
 
The Ring programming language version 1.8 book - Part 25 of 202
The Ring programming language version 1.8 book - Part 25 of 202The Ring programming language version 1.8 book - Part 25 of 202
The Ring programming language version 1.8 book - Part 25 of 202
 
The Ring programming language version 1.5.2 book - Part 26 of 181
The Ring programming language version 1.5.2 book - Part 26 of 181The Ring programming language version 1.5.2 book - Part 26 of 181
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.5.1 book - Part 19 of 180The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.5.1 book - Part 19 of 180
 
The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88The Ring programming language version 1.3 book - Part 18 of 88
The Ring programming language version 1.3 book - Part 18 of 88
 
The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84
 
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202
 
The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196The Ring programming language version 1.7 book - Part 25 of 196
The Ring programming language version 1.7 book - Part 25 of 196
 
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88
 
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181
 
The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31The Ring programming language version 1.5 book - Part 3 of 31
The Ring programming language version 1.5 book - Part 3 of 31
 
The Ring programming language version 1.5.3 book - Part 19 of 184
The Ring programming language version 1.5.3 book - Part 19 of 184The Ring programming language version 1.5.3 book - Part 19 of 184
The Ring programming language version 1.5.3 book - Part 19 of 184
 
The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189The Ring programming language version 1.6 book - Part 183 of 189
The Ring programming language version 1.6 book - Part 183 of 189
 
The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196The Ring programming language version 1.7 book - Part 26 of 196
The Ring programming language version 1.7 book - Part 26 of 196
 

More from Mahmoud Samir Fayed

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

More from Mahmoud Samir Fayed (20)

The Ring programming language version 1.10 book - Part 212 of 212
The Ring programming language version 1.10 book - Part 212 of 212The Ring programming language version 1.10 book - Part 212 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 211 of 212The Ring programming language version 1.10 book - Part 211 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 210 of 212The Ring programming language version 1.10 book - Part 210 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 208 of 212The Ring programming language version 1.10 book - Part 208 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 207 of 212The Ring programming language version 1.10 book - Part 207 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 205 of 212The Ring programming language version 1.10 book - Part 205 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 206 of 212The Ring programming language version 1.10 book - Part 206 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 204 of 212The Ring programming language version 1.10 book - Part 204 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 203 of 212The Ring programming language version 1.10 book - Part 203 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 202 of 212The Ring programming language version 1.10 book - Part 202 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 201 of 212The Ring programming language version 1.10 book - Part 201 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 200 of 212The Ring programming language version 1.10 book - Part 200 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 199 of 212The Ring programming language version 1.10 book - Part 199 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 198 of 212The Ring programming language version 1.10 book - Part 198 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 197 of 212The Ring programming language version 1.10 book - Part 197 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 196 of 212The Ring programming language version 1.10 book - Part 196 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 195 of 212The Ring programming language version 1.10 book - Part 195 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 194 of 212The Ring programming language version 1.10 book - Part 194 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 193 of 212The Ring programming language version 1.10 book - Part 193 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
The Ring programming language version 1.10 book - Part 192 of 212The Ring programming language version 1.10 book - Part 192 of 212
The Ring programming language version 1.10 book - Part 192 of 212
 

Recently uploaded

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 

Recently uploaded (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 

The Ring programming language version 1.5.3 book - Part 20 of 184

  • 1. Ring Documentation, Release 1.5.3 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 19.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: 19.2. Looping 165
  • 2. Ring Documentation, Release 1.5.3 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 19.3 Exceptions try Block of statements catch Block of statements end 19.3. Exceptions 166
  • 3. CHAPTER TWENTY 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. 20.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") } 167
  • 4. Ring Documentation, Release 1.5.3 • 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") } 20.2 Looping • While Loop Syntax: while Expression { Block of statements } Example: Load "stdlib.ring" While True { print(" Main Menu --------- 20.2. Looping 168
  • 5. Ring Documentation, Release 1.5.3 (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") } 20.2. Looping 169
  • 6. Ring Documentation, Release 1.5.3 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 20.3 Exceptions 20.3. Exceptions 170
  • 7. Ring Documentation, Release 1.5.3 try { Block of statements catch Block of statements } 20.3. Exceptions 171
  • 8. CHAPTER TWENTYONE GETTING INPUT We can get input from the keyboard using • The Give Command • The GetChar() Function • The Input() Function 21.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 21.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() 172
  • 9. Ring Documentation, Release 1.5.3 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 21.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 21.3. Input() Function 173
  • 10. CHAPTER TWENTYTWO 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 22.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 22.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: 174