SlideShare a Scribd company logo
Ring Documentation, Release 1.2
15.4 Using For in to modify lists
When we use (For in) we get items by reference.
This means that we can read/edit items inside the loop.
Example:
aList = 1:5 # create list contains numbers from 1 to 5
# replace list numbers with strings
for x in aList
switch x
on 1 x = "one"
on 2 x = "two"
on 3 x = "three"
on 4 x = "four"
on 5 x = "five"
off
next
see aList # print the list items
15.5 Do Again Loop
Syntax:
do
Block of statements
again expression
Example:
x = 1
do
see x + nl
x++
again x <= 10
15.6 Exit Command
Used to go outside one or more of loops.
Syntax:
exit [expression] # inside loop
Example:
for x = 1 to 10
see x + nl
if x = 5 exit ok
next
15.4. Using For in to modify lists 70
Ring Documentation, Release 1.2
15.7 Exit from two loops
The next example presents how to use the exit command to exit from two loops in one jump.
Example:
for x = 1 to 10
for y = 1 to 10
see "x=" + x + " y=" + y + nl
if x = 3 and y = 5
exit 2 # exit from 2 loops
ok
next
next
• Loop Command
Used to jump to the next iteration in the loop.
Syntax:
loop [expression] # inside loop
Example:
for x = 1 to 10
if x = 3
see "Number Three" + nl
loop
ok
see x + nl
next
15.8 Exit/Loop inside sub functions
While we are inside a loop, we can call a function then use the exit and/or loop command inside that function and the
command will work on the outer loop.
Example:
# print numbers from 1 to 10 except number 5.
for x = 1 to 10
ignore(x,5)
see x + nl
next
func ignore x,y
if x = y
loop
ok
15.9 Short-circuit evaluation
The logical operators and/or follow the short-circuit evaluation.
15.7. Exit from two loops 71
Ring Documentation, Release 1.2
If the first argument of the AND operator is zero, then there is no need to evaluate the second argument and the result
will be zero.
If the first argument of the OR operator is one, then there is no need to evaluate the second argument and the result
will be one.
Example:
/* output
** nice
** nice
** great
*/
x = 0 y = 10
if (x = 0 and nice()) and (y = 10 and nice())
see "great" + nl
ok
func nice see "nice" + nl return 1
Example:
# No output
x = 0 y = 10
if (x = 1 and nice()) and (y = 10 and nice())
see "great" + nl
ok
func nice see "nice" + nl return 1
Example:
/* output
** nice
** great
*/
x = 0 y = 10
if (x = 0 and nice()) or (y = 10 and nice())
see "great" + nl
ok
func nice see "nice" + nl return 1
15.10 Comments about evaluation
• True, False, nl & NULL are variables defined by the language
• True = 1
• False = 0
• nl = new line
• NULL = empty string = “”
15.10. Comments about evaluation 72
Ring Documentation, Release 1.2
• Everything evaluates to true except 0 (False).
Example:
# output = message from the if statement
if 5 # 5 evaluates to true because it's not zero (0).
see "message from the if statement" + nl
ok
15.10. Comments about evaluation 73
CHAPTER
SIXTEEN
CONTROL STRUCTURES - SECOND STYLE
In this chapter we are going to learn about the second style of control structures provided by the Ring programming
language.
16.1 Branching
• If Statement
Syntax:
if Expression
Block of statements
elseif Expression
Block of statements
else
Block of statements
end
Example:
put "
Main Menu
---------
(1) Say Hello
(2) About
(3) Exit
" get nOption
if nOption = 1 put "Enter your name : " get name put "Hello " + name + nl
elseif nOption = 2 put "Sample : using if statement" + nl
elseif nOption = 3 bye
else put "bad option..." + nl
end
• Switch Statement
Syntax:
switch Expression
case Expression
Block of statements
else
Block of statements
end
74
Ring Documentation, Release 1.2
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
16.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:
16.2. Looping 75
Ring Documentation, Release 1.2
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
16.3 Exceptions
try
Block of statements
catch
Block of statements
end
16.3. Exceptions 76
CHAPTER
SEVENTEEN
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.
17.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")
}
77
Ring Documentation, Release 1.2
• 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")
}
17.2 Looping
• While Loop
Syntax:
while Expression {
Block of statements
}
Example:
Load "stdlib.ring"
While True {
print("
Main Menu
---------
17.2. Looping 78
Ring Documentation, Release 1.2
(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")
}
17.2. Looping 79

More Related Content

What's hot (20)

PDF
The Ring programming language version 1.9 book - Part 27 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 22 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 19 of 185
Mahmoud Samir Fayed
 
PPTX
Dictionary
Pooja B S
 
PDF
The Ring programming language version 1.8 book - Part 24 of 202
Mahmoud Samir Fayed
 
PPTX
Iteration
Pooja B S
 
PPTX
String Manipulation in Python
Pooja B S
 
PDF
The Ring programming language version 1.4 book - Part 5 of 30
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.4.1 book - Part 5 of 31
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 19 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 22 of 189
Mahmoud Samir Fayed
 
PPTX
Functions & Recursion
Nishant Munjal
 
PDF
The Ring programming language version 1.5.2 book - Part 31 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 17 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 27 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 31 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 21 of 84
Mahmoud Samir Fayed
 
PDF
Swift the implicit parts
Maxim Zaks
 
PDF
The Ring programming language version 1.9 book - Part 26 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 27 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 22 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 19 of 185
Mahmoud Samir Fayed
 
Dictionary
Pooja B S
 
The Ring programming language version 1.8 book - Part 24 of 202
Mahmoud Samir Fayed
 
Iteration
Pooja B S
 
String Manipulation in Python
Pooja B S
 
The Ring programming language version 1.4 book - Part 5 of 30
Mahmoud Samir Fayed
 
The Ring programming language version 1.4.1 book - Part 5 of 31
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 19 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 22 of 189
Mahmoud Samir Fayed
 
Functions & Recursion
Nishant Munjal
 
The Ring programming language version 1.5.2 book - Part 31 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 17 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 27 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 31 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 21 of 84
Mahmoud Samir Fayed
 
Swift the implicit parts
Maxim Zaks
 
The Ring programming language version 1.9 book - Part 26 of 210
Mahmoud Samir Fayed
 

Viewers also liked (20)

PDF
Guillermo Dumrauf - Calculo Financiero Aplicado (Parte 2 de 3)
Fabi frewq
 
PDF
Nk 03 2017_lr_englisch
Zissis Ahladas
 
PDF
The Ring programming language version 1.2 book - Part 8 of 84
Mahmoud Samir Fayed
 
PPTX
V. cholerae
Samer Bio
 
PDF
人気プログラム 一覧
ZAC Inc,.
 
PPTX
Gpl1 8-artikel-tutorial 1
fnfm
 
PDF
High Temperature Conveyor Belts
Petrorays Products Co.
 
PDF
The Ring programming language version 1.2 book - Part 7 of 84
Mahmoud Samir Fayed
 
PDF
Ambientação ADM - dicas de navegação - 1º semestre 2017
Henrique Oliveira
 
PDF
The Ring programming language version 1.2 book - Part 14 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 27 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 36 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 13 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 38 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 29 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 28 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 32 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 30 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 35 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 39 of 84
Mahmoud Samir Fayed
 
Guillermo Dumrauf - Calculo Financiero Aplicado (Parte 2 de 3)
Fabi frewq
 
Nk 03 2017_lr_englisch
Zissis Ahladas
 
The Ring programming language version 1.2 book - Part 8 of 84
Mahmoud Samir Fayed
 
V. cholerae
Samer Bio
 
人気プログラム 一覧
ZAC Inc,.
 
Gpl1 8-artikel-tutorial 1
fnfm
 
High Temperature Conveyor Belts
Petrorays Products Co.
 
The Ring programming language version 1.2 book - Part 7 of 84
Mahmoud Samir Fayed
 
Ambientação ADM - dicas de navegação - 1º semestre 2017
Henrique Oliveira
 
The Ring programming language version 1.2 book - Part 14 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 27 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 36 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 13 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 38 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 29 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 28 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 32 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 30 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 35 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 39 of 84
Mahmoud Samir Fayed
 
Ad

Similar to The Ring programming language version 1.2 book - Part 10 of 84 (20)

PDF
The Ring programming language version 1.5.1 book - Part 18 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 19 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 12 of 88
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 20 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 23 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 20 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.6 book - Part 21 of 189
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 28 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 71 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 72 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 86 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 84 of 184
Mahmoud Samir Fayed
 
PPTX
Chapter 2-Python and control flow statement.pptx
atharvdeshpande20
 
PDF
The Ring programming language version 1.8 book - Part 82 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 57 of 88
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 18 of 88
Mahmoud Samir Fayed
 
PPTX
“Python” or “CPython” is written in C/C+
Mukeshpanigrahy1
 
PDF
The Ring programming language version 1.7 book - Part 79 of 196
Mahmoud Samir Fayed
 
PPTX
Python programing
hamzagame
 
PDF
The Ring programming language version 1.2 book - Part 54 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 18 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 19 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 12 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 20 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 23 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 20 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.6 book - Part 21 of 189
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 28 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 71 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 72 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 86 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 84 of 184
Mahmoud Samir Fayed
 
Chapter 2-Python and control flow statement.pptx
atharvdeshpande20
 
The Ring programming language version 1.8 book - Part 82 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 57 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 18 of 88
Mahmoud Samir Fayed
 
“Python” or “CPython” is written in C/C+
Mukeshpanigrahy1
 
The Ring programming language version 1.7 book - Part 79 of 196
Mahmoud Samir Fayed
 
Python programing
hamzagame
 
The Ring programming language version 1.2 book - Part 54 of 84
Mahmoud Samir Fayed
 
Ad

More from Mahmoud Samir Fayed (20)

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

Recently uploaded (20)

PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Tally software_Introduction_Presentation
AditiBansal54083
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 

The Ring programming language version 1.2 book - Part 10 of 84

  • 1. Ring Documentation, Release 1.2 15.4 Using For in to modify lists When we use (For in) we get items by reference. This means that we can read/edit items inside the loop. Example: aList = 1:5 # create list contains numbers from 1 to 5 # replace list numbers with strings for x in aList switch x on 1 x = "one" on 2 x = "two" on 3 x = "three" on 4 x = "four" on 5 x = "five" off next see aList # print the list items 15.5 Do Again Loop Syntax: do Block of statements again expression Example: x = 1 do see x + nl x++ again x <= 10 15.6 Exit Command Used to go outside one or more of loops. Syntax: exit [expression] # inside loop Example: for x = 1 to 10 see x + nl if x = 5 exit ok next 15.4. Using For in to modify lists 70
  • 2. Ring Documentation, Release 1.2 15.7 Exit from two loops The next example presents how to use the exit command to exit from two loops in one jump. Example: for x = 1 to 10 for y = 1 to 10 see "x=" + x + " y=" + y + nl if x = 3 and y = 5 exit 2 # exit from 2 loops ok next next • Loop Command Used to jump to the next iteration in the loop. Syntax: loop [expression] # inside loop Example: for x = 1 to 10 if x = 3 see "Number Three" + nl loop ok see x + nl next 15.8 Exit/Loop inside sub functions While we are inside a loop, we can call a function then use the exit and/or loop command inside that function and the command will work on the outer loop. Example: # print numbers from 1 to 10 except number 5. for x = 1 to 10 ignore(x,5) see x + nl next func ignore x,y if x = y loop ok 15.9 Short-circuit evaluation The logical operators and/or follow the short-circuit evaluation. 15.7. Exit from two loops 71
  • 3. Ring Documentation, Release 1.2 If the first argument of the AND operator is zero, then there is no need to evaluate the second argument and the result will be zero. If the first argument of the OR operator is one, then there is no need to evaluate the second argument and the result will be one. Example: /* output ** nice ** nice ** great */ x = 0 y = 10 if (x = 0 and nice()) and (y = 10 and nice()) see "great" + nl ok func nice see "nice" + nl return 1 Example: # No output x = 0 y = 10 if (x = 1 and nice()) and (y = 10 and nice()) see "great" + nl ok func nice see "nice" + nl return 1 Example: /* output ** nice ** great */ x = 0 y = 10 if (x = 0 and nice()) or (y = 10 and nice()) see "great" + nl ok func nice see "nice" + nl return 1 15.10 Comments about evaluation • True, False, nl & NULL are variables defined by the language • True = 1 • False = 0 • nl = new line • NULL = empty string = “” 15.10. Comments about evaluation 72
  • 4. Ring Documentation, Release 1.2 • Everything evaluates to true except 0 (False). Example: # output = message from the if statement if 5 # 5 evaluates to true because it's not zero (0). see "message from the if statement" + nl ok 15.10. Comments about evaluation 73
  • 5. CHAPTER SIXTEEN CONTROL STRUCTURES - SECOND STYLE In this chapter we are going to learn about the second style of control structures provided by the Ring programming language. 16.1 Branching • If Statement Syntax: if Expression Block of statements elseif Expression Block of statements else Block of statements end Example: put " Main Menu --------- (1) Say Hello (2) About (3) Exit " get nOption if nOption = 1 put "Enter your name : " get name put "Hello " + name + nl elseif nOption = 2 put "Sample : using if statement" + nl elseif nOption = 3 bye else put "bad option..." + nl end • Switch Statement Syntax: switch Expression case Expression Block of statements else Block of statements end 74
  • 6. Ring Documentation, Release 1.2 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 16.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: 16.2. Looping 75
  • 7. Ring Documentation, Release 1.2 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 16.3 Exceptions try Block of statements catch Block of statements end 16.3. Exceptions 76
  • 8. CHAPTER SEVENTEEN 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. 17.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") } 77
  • 9. Ring Documentation, Release 1.2 • 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") } 17.2 Looping • While Loop Syntax: while Expression { Block of statements } Example: Load "stdlib.ring" While True { print(" Main Menu --------- 17.2. Looping 78
  • 10. Ring Documentation, Release 1.2 (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") } 17.2. Looping 79