Ring Documentation Walkthrough #5 – If & Switch statements

If Statement:

It is the most used statements in any app.
In Ring, the If statement is pretty clear and easy to understand.

if Expression #Start
        your code
but Expression
        your code
else
        your code
ok #End

It’s more like a combination of VisualBasic.net and Python.

Example:

see "Which OS does your mobile run ?" + nl
see "Please select one from the list below :
  (1) - Android 6.0.1 (Marshmallow)
  (2) - Android 5.0 to 5.1.x (Lollipop)
  (3) - Android 4.4 to 4.4.4 (KitKat)
  (4) - iOS 9
  (5) - Firefox OS"+ nl
give answer #returns a string value

if answer = "1"
 see 'Marshmallow!, good for you.'
but answer = "2"
 see 'Lollipop ?!, are you a Samsung user ?'
but answer = "3"
 see "KitKat, are you a Samsung user too ?"
but answer = "4"
 see "There's a site called crashsafari.com, don't open it."
but answer = "5"
 see "A moment of silence for the iOS users."
else
 see '...'
ok

Note : you can use the code after if statement just in the same line (inline format) or like python with just a tab, you have the ability to use what you see is perfect for you and the code.

Example:

If something happened do something
but something else happened do something else
ok
#or like python
If something happened
      do something
ok

Switch Statement:

switch Expression #Start
on Expression
        your code
other
        your code
off #End

Easy and Clear.

Example:

the previous example but with Switch Statement instead of If Statement

see "Which OS your mobile runs ?" + nl
see "Please select one from the list below :
 (1) - Android 6.0.1 (Marshmallow)
 (2) - Android 5.0 to 5.1.x (Lollipop)
 (3) - Android 4.4 to 4.4.4 (KitKat)
 (4) - iOS 9
 (5) - Firefox OS"+ nl
give answer #returns a string value

switch answer
on "1"
 see 'Marshmallow!, good for you.'
on "2"
 see 'Lollipop ?!, are you a Samsung user ?'
on "3"
 see "KitKat, are you a Samsung user too ?"
on "4"
 see "There's a site called crashsafari.com, don't open it."
but answer = "5"
 see "A moment of silence for the iOS users."
other
 see 'Choose on of the list.'
off

#you can also do it in the inline format:
on "1" see '....'

#or
on "1"
       see '....' #Pythonic way

Note: I’ve used both and in the strings in the examples above.

amrESSAM.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s