Hello Charles,
Here is my proposal:
Add the each and the when keywords and allow this:
do
' some loop code...
end do
do while x <= 42
' some loop code...
end do
do
' some loop code...
end do when x == 42
do for x = 0 to x == 42 do x++
' some loop code...
end do
do for each x[]
' some loop code...
end do
Why this would be cool?
It not only adds syntactic sugar but allowes to add aliases to loops.
What are loop aliases you ask?
Imagine you have some nice loops inside loops inside etc.
A problem arises when you want to break out of the loop and do:
do
' some loop code...
if x == 42 then break end if
' more loop code...
end do
This is easy, but what about this:
do
' some loop code...
if x == 42 then
break
' more loop code...
else
do
' some loop code...
if y == 84 then break end if
' more loop code...
end do
' even more loop code...
end do
If y equals 84 the code breaks out of the inner loop, but what if you want to break out of the outer loop as well, or you have more than 2 loops and several conditionals?
One way is to use goto and depending on the size of the code you end up with spaghetti code.
The other solution is to use loop aliases. Example:
(keep in mind: I don't insist on the curly brackets...)
do {banana}
' some loop code...
if x == 42 then
break
' more loop code...
else
do {apple}
' some loop code...
if y == 84 then exit {apple} end if
' more loop code...
end do
' even more loop code...
do {citroen}
' some loop code...
if z == 21 then exit {banana} end if
' more loop code...
end do
' even more loop code...
end do
And then the following code can start right after the loop and you don't have to jump around your code with a bunch of gotos.
BTW: Stuff like this should work as well:
do {banana} while x <= 42
' some loop code...
end do
Thanks for reading.
efgee
EDIT: changed the loop keyword to do.