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 (....) 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.
It’s a combination of python and VisualBasic.NET.
for x = 1 to 10 see x next #or for x = 1 to 10 see x next #inline format ?!
for x = 10 to 0 step -1 see x + nl #newline next
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
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.