Ring Documentation Walkthrough #5.1 – Loops

Of course loops are so important in any app you create, so in Ring it’s so simple to work with.

Let’s discuss at the beginning the While Loop.


While Loop:

while (....)
       your code... #pythonic way
#or you can write it here, while it's in the range before 'end' and after while.
end

It’s familiar, no need for examples here.


For Loop:

It’s a combination of python and VisualBasic.NET.

Example :

for x = 1 to 10
    see x
next
#or
for x = 1 to 10 see x next #inline format ?!

Example 2:

for x = 10 to 0 step -1
     see x + nl #newline
next

Example 3:

list = [1,2,3,4,5]
for i in list
   see i + nl
next
list = ['amr', 'ahmed', 'youssef']
for i in list see i + ' ' next #inline format

Example 4 – Editing lists through the For Loop:

P.S. the example by : Eng. Mahmoud Samir.

aList = 1:3
see aList
for x in aList
switch x 
on 1 x = "one"
on 2 x = "two"
on 3 x = "three"
off
next
see aList

Do Again Loop:

do
     your code ...
again 

Example :

x = 10
do
        see x + nl
        x--
again x > 0

Last two things to add,

In python we use continue to keep the loop looping, and the word break

In ring we are using loop to keep it looping as continue, and the word exit to cut off the loop as break


I will talk about some little things in the next post to stop there and make a training post, that includes examples, problems, small apps .. etc.

Thank you.

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