SlideShare a Scribd company logo
Ring Documentation, Release 1.5.3
17.4 Bitwise Operators
The next table presents all of the bitwise operators provided by the Ring language. Assume variable X=8 and variable
Y=2 then:
Operator Description Example Result
& Binary AND x & y 0
| Binary OR x | y 10
^ Binary XOR x ^ y 10
~ Binary Ones Complement ~x -9
<< Binary Left Shift x << y 32
>> Binary Right Shift x >> y 2
17.5 Assignment Operators
The next table presents all of the assignment operators provided by the Ring language.
Assume variable X=8 then:
Operator Description Example Result
= Assignment x = 10 x=10
+= Add AND assignment x += 5 x=13
-= Subtract AND assignment x -= 3 x=5
*= Multiply AND assignment x *= 2 x=16
/= Divide AND assignment x /= 3 x=2.67
%= Modulus AND assignment x %= 2 x=0
<<= Left shift AND assignment x <<= 2 x=32
>>= Right shift AND assignment x >>= 2 x=2
&= Bitwise AND assignment x &= 4 x=0
|= Bitwise OR and assignment x |= 3 x=11
^= Bitwise XOR and assignment x ^= 4 x=12
17.6 Misc Operators
Operator Description
:literal using : before identifier mean literal
Start:End create list contains items from start to end
[list items] define list items
list[index] access list item
obj.name using the dot operator to access object members (attributes/methods).
obj {stmts} execute statements with direct access to object attributes & methods
func(para,...) call function using parameters separated by comma
17.7 Operators Precedence
The next table present operators from higher precedence (Evaluated first) to lower precedence.
17.4. Bitwise Operators 155
Ring Documentation, Release 1.5.3
Operator
. [] () {}
- ~ :Literal [list items]
++ - -
Start:End
* / %
+ -
<< >>
&
| ^
< > <= >=
= !=
not
and or
Assignment = += -= *= /= %=>>= <<= &= ^= |=
Example:
See 3+5*4 # prints 23
17.7. Operators Precedence 156
CHAPTER
EIGHTEEN
CONTROL STRUCTURES - FIRST STYLE
In this chapter we are going to learn about the control structures provided by the Ring programming language.
18.1 Branching
• If Statement
Syntax:
if Expression
Block of statements
but Expression
Block of statements
else
Block of statements
ok
Example:
see "
Main Menu
---------
(1) Say Hello
(2) About
(3) Exit
" give nOption
if nOption = 1 see "Enter your name : " give name see "Hello " + name + nl
but nOption = 2 see "Sample : using if statement" + nl
but nOption = 3 bye
else see "bad option..." + nl
ok
• Switch Statement
Syntax:
switch Expression
on Expression
Block of statements
other
Block of statements
off
157
Ring Documentation, Release 1.5.3
Example:
See "
Main Menu
---------
(1) Say Hello
(2) About
(3) Exit
" Give nOption
Switch nOption
On 1 See "Enter your name : " Give name See "Hello " + name + nl
On 2 See "Sample : using switch statement" + nl
On 3 Bye
Other See "bad option..." + nl
Off
18.2 Looping
• While Loop
Syntax:
while Expression
Block of statements
end
Example:
While True
See "
Main Menu
---------
(1) Say Hello
(2) About
(3) Exit
" Give nOption
Switch nOption
On 1
See "Enter your name : "
Give name
See "Hello " + name + nl
On 2
See "Sample : using while loop" + nl
On 3
Bye
Other
See "bad option..." + nl
Off
End
• For Loop
Syntax:
18.2. Looping 158
Ring Documentation, Release 1.5.3
for identifier=expression to expression [step expression]
Block of statements
next
Example:
# print numbers from 1 to 10
for x = 1 to 10 see x + nl next
Example:
# Dynamic loop
See "Start : " give nStart
See "End : " give nEnd
See "Step : " give nStep
For x = nStart to nEnd Step nStep
see x + nl
Next
Example:
# print even numbers from 0 to 10
for x = 0 to 10 step 2
see x + nl
next
Example:
# print even numbers from 10 to 0
for x = 10 to 0 step -2
see x + nl
next
• For in Loop
Syntax:
for identifier in List/String [step expression]
Block of statements
next
Example:
aList = 1:10 # create list contains numbers from 1 to 10
for x in aList see x + nl next # print numbers from 1 to 10
18.3 Using The Step option with For in
We can use the Step option with For in to skip number of items in each iteration
Example:
aList = 1:10 # create list contains numbers from 1 to 10
# print odd items inside the list
for x in aList step 2
see x + nl
next
18.3. Using The Step option with For in 159
Ring Documentation, Release 1.5.3
18.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
18.5 Do Again Loop
Syntax:
do
Block of statements
again expression
Example:
x = 1
do
see x + nl
x++
again x <= 10
18.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
18.4. Using For in to modify lists 160
Ring Documentation, Release 1.5.3
18.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
18.8 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
18.9 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
18.7. Exit from two loops 161
Ring Documentation, Release 1.5.3
18.10 Short-circuit evaluation
The logical operators and/or follow the short-circuit evaluation.
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
18.11 Comments about evaluation
• True, False, nl & NULL are variables defined by the language
• True = 1
18.10. Short-circuit evaluation 162
Ring Documentation, Release 1.5.3
• False = 0
• nl = new line
• NULL = empty string = “”
• 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
18.11. Comments about evaluation 163
CHAPTER
NINETEEN
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.
19.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
164

More Related Content

PDF
The Ring programming language version 1.6 book - Part 21 of 189
PDF
The Ring programming language version 1.7 book - Part 22 of 196
PDF
The Ring programming language version 1.5.4 book - Part 19 of 185
PDF
The Ring programming language version 1.10 book - Part 27 of 212
PDF
The Ring programming language version 1.8 book - Part 24 of 202
PDF
The Ring programming language version 1.3 book - Part 11 of 88
PDF
The Ring programming language version 1.4.1 book - Part 5 of 31
PDF
The Ring programming language version 1.5.2 book - Part 18 of 181
The Ring programming language version 1.6 book - Part 21 of 189
The Ring programming language version 1.7 book - Part 22 of 196
The Ring programming language version 1.5.4 book - Part 19 of 185
The Ring programming language version 1.10 book - Part 27 of 212
The Ring programming language version 1.8 book - Part 24 of 202
The Ring programming language version 1.3 book - Part 11 of 88
The Ring programming language version 1.4.1 book - Part 5 of 31
The Ring programming language version 1.5.2 book - Part 18 of 181

What's hot (20)

PDF
The Ring programming language version 1.2 book - Part 10 of 84
PDF
The Ring programming language version 1.2 book - Part 9 of 84
PDF
The Ring programming language version 1.4 book - Part 5 of 30
PDF
The Ring programming language version 1.2 book - Part 11 of 84
PDF
The Ring programming language version 1.2 book - Part 12 of 84
PDF
The Ring programming language version 1.5.2 book - Part 19 of 181
PDF
The Ring programming language version 1.5.1 book - Part 18 of 180
PDF
The Ring programming language version 1.9 book - Part 26 of 210
PPSX
Nested loops
PDF
Nesting of for loops using C++
PPTX
Working of while loop
PPTX
Iterative control structures, looping, types of loops, loop working
PDF
The Ring programming language version 1.8 book - Part 25 of 202
PPTX
Python Conditionals and Functions
DOCX
Mcq cpup
PDF
The Ring programming language version 1.9 book - Part 27 of 210
PDF
Introduction to python programming
PDF
The Ring programming language version 1.5.1 book - Part 19 of 180
PDF
The Ring programming language version 1.9 book - Part 25 of 210
The Ring programming language version 1.2 book - Part 10 of 84
The Ring programming language version 1.2 book - Part 9 of 84
The Ring programming language version 1.4 book - Part 5 of 30
The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 12 of 84
The Ring programming language version 1.5.2 book - Part 19 of 181
The Ring programming language version 1.5.1 book - Part 18 of 180
The Ring programming language version 1.9 book - Part 26 of 210
Nested loops
Nesting of for loops using C++
Working of while loop
Iterative control structures, looping, types of loops, loop working
The Ring programming language version 1.8 book - Part 25 of 202
Python Conditionals and Functions
Mcq cpup
The Ring programming language version 1.9 book - Part 27 of 210
Introduction to python programming
The Ring programming language version 1.5.1 book - Part 19 of 180
The Ring programming language version 1.9 book - Part 25 of 210
Ad

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

PDF
The Ring programming language version 1.5.1 book - Part 17 of 180
PDF
The Ring programming language version 1.5.4 book - Part 20 of 185
PDF
The Ring programming language version 1.3 book - Part 12 of 88
PDF
The Ring programming language version 1.8 book - Part 23 of 202
PDF
The Ring programming language version 1.7 book - Part 23 of 196
PDF
The Ring programming language version 1.5.3 book - Part 20 of 184
PDF
The Ring programming language version 1.6 book - Part 22 of 189
PPTX
Chapter 2-Python and control flow statement.pptx
PDF
The Ring programming language version 1.10 book - Part 28 of 212
PDF
The Ring programming language version 1.5.3 book - Part 18 of 184
PDF
The Ring programming language version 1.10 book - Part 31 of 212
PPT
PPT
Java - Operators
PPTX
Pythonlearn-03-Conditional.pptx
PPTX
“Python” or “CPython” is written in C/C+
PPTX
Python programing
PPTX
Bikalpa_Thapa_Python_Programming_(Basics).pptx
PPTX
made it easy: python quick reference for beginners
PPT
Operators
PDF
The Ring programming language version 1.2 book - Part 13 of 84
The Ring programming language version 1.5.1 book - Part 17 of 180
The Ring programming language version 1.5.4 book - Part 20 of 185
The Ring programming language version 1.3 book - Part 12 of 88
The Ring programming language version 1.8 book - Part 23 of 202
The Ring programming language version 1.7 book - Part 23 of 196
The Ring programming language version 1.5.3 book - Part 20 of 184
The Ring programming language version 1.6 book - Part 22 of 189
Chapter 2-Python and control flow statement.pptx
The Ring programming language version 1.10 book - Part 28 of 212
The Ring programming language version 1.5.3 book - Part 18 of 184
The Ring programming language version 1.10 book - Part 31 of 212
Java - Operators
Pythonlearn-03-Conditional.pptx
“Python” or “CPython” is written in C/C+
Python programing
Bikalpa_Thapa_Python_Programming_(Basics).pptx
made it easy: python quick reference for beginners
Operators
The Ring programming language version 1.2 book - Part 13 of 84
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
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
Approach and Philosophy of On baking technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Encapsulation theory and applications.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Cloud computing and distributed systems.
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction
Approach and Philosophy of On baking technology
Per capita expenditure prediction using model stacking based on satellite ima...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
MIND Revenue Release Quarter 2 2025 Press Release
The AUB Centre for AI in Media Proposal.docx
Spectral efficient network and resource selection model in 5G networks
Encapsulation theory and applications.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Cloud computing and distributed systems.
Network Security Unit 5.pdf for BCA BBA.
Understanding_Digital_Forensics_Presentation.pptx
MYSQL Presentation for SQL database connectivity
Mobile App Security Testing_ A Comprehensive Guide.pdf
Unlocking AI with Model Context Protocol (MCP)
Reach Out and Touch Someone: Haptics and Empathic Computing

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

  • 1. Ring Documentation, Release 1.5.3 17.4 Bitwise Operators The next table presents all of the bitwise operators provided by the Ring language. Assume variable X=8 and variable Y=2 then: Operator Description Example Result & Binary AND x & y 0 | Binary OR x | y 10 ^ Binary XOR x ^ y 10 ~ Binary Ones Complement ~x -9 << Binary Left Shift x << y 32 >> Binary Right Shift x >> y 2 17.5 Assignment Operators The next table presents all of the assignment operators provided by the Ring language. Assume variable X=8 then: Operator Description Example Result = Assignment x = 10 x=10 += Add AND assignment x += 5 x=13 -= Subtract AND assignment x -= 3 x=5 *= Multiply AND assignment x *= 2 x=16 /= Divide AND assignment x /= 3 x=2.67 %= Modulus AND assignment x %= 2 x=0 <<= Left shift AND assignment x <<= 2 x=32 >>= Right shift AND assignment x >>= 2 x=2 &= Bitwise AND assignment x &= 4 x=0 |= Bitwise OR and assignment x |= 3 x=11 ^= Bitwise XOR and assignment x ^= 4 x=12 17.6 Misc Operators Operator Description :literal using : before identifier mean literal Start:End create list contains items from start to end [list items] define list items list[index] access list item obj.name using the dot operator to access object members (attributes/methods). obj {stmts} execute statements with direct access to object attributes & methods func(para,...) call function using parameters separated by comma 17.7 Operators Precedence The next table present operators from higher precedence (Evaluated first) to lower precedence. 17.4. Bitwise Operators 155
  • 2. Ring Documentation, Release 1.5.3 Operator . [] () {} - ~ :Literal [list items] ++ - - Start:End * / % + - << >> & | ^ < > <= >= = != not and or Assignment = += -= *= /= %=>>= <<= &= ^= |= Example: See 3+5*4 # prints 23 17.7. Operators Precedence 156
  • 3. CHAPTER EIGHTEEN CONTROL STRUCTURES - FIRST STYLE In this chapter we are going to learn about the control structures provided by the Ring programming language. 18.1 Branching • If Statement Syntax: if Expression Block of statements but Expression Block of statements else Block of statements ok Example: see " Main Menu --------- (1) Say Hello (2) About (3) Exit " give nOption if nOption = 1 see "Enter your name : " give name see "Hello " + name + nl but nOption = 2 see "Sample : using if statement" + nl but nOption = 3 bye else see "bad option..." + nl ok • Switch Statement Syntax: switch Expression on Expression Block of statements other Block of statements off 157
  • 4. Ring Documentation, Release 1.5.3 Example: See " Main Menu --------- (1) Say Hello (2) About (3) Exit " Give nOption Switch nOption On 1 See "Enter your name : " Give name See "Hello " + name + nl On 2 See "Sample : using switch statement" + nl On 3 Bye Other See "bad option..." + nl Off 18.2 Looping • While Loop Syntax: while Expression Block of statements end Example: While True See " Main Menu --------- (1) Say Hello (2) About (3) Exit " Give nOption Switch nOption On 1 See "Enter your name : " Give name See "Hello " + name + nl On 2 See "Sample : using while loop" + nl On 3 Bye Other See "bad option..." + nl Off End • For Loop Syntax: 18.2. Looping 158
  • 5. Ring Documentation, Release 1.5.3 for identifier=expression to expression [step expression] Block of statements next Example: # print numbers from 1 to 10 for x = 1 to 10 see x + nl next Example: # Dynamic loop See "Start : " give nStart See "End : " give nEnd See "Step : " give nStep For x = nStart to nEnd Step nStep see x + nl Next Example: # print even numbers from 0 to 10 for x = 0 to 10 step 2 see x + nl next Example: # print even numbers from 10 to 0 for x = 10 to 0 step -2 see x + nl next • For in Loop Syntax: for identifier in List/String [step expression] Block of statements next Example: aList = 1:10 # create list contains numbers from 1 to 10 for x in aList see x + nl next # print numbers from 1 to 10 18.3 Using The Step option with For in We can use the Step option with For in to skip number of items in each iteration Example: aList = 1:10 # create list contains numbers from 1 to 10 # print odd items inside the list for x in aList step 2 see x + nl next 18.3. Using The Step option with For in 159
  • 6. Ring Documentation, Release 1.5.3 18.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 18.5 Do Again Loop Syntax: do Block of statements again expression Example: x = 1 do see x + nl x++ again x <= 10 18.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 18.4. Using For in to modify lists 160
  • 7. Ring Documentation, Release 1.5.3 18.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 18.8 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 18.9 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 18.7. Exit from two loops 161
  • 8. Ring Documentation, Release 1.5.3 18.10 Short-circuit evaluation The logical operators and/or follow the short-circuit evaluation. 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 18.11 Comments about evaluation • True, False, nl & NULL are variables defined by the language • True = 1 18.10. Short-circuit evaluation 162
  • 9. Ring Documentation, Release 1.5.3 • False = 0 • nl = new line • NULL = empty string = “” • 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 18.11. Comments about evaluation 163
  • 10. CHAPTER NINETEEN 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. 19.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 164