What Xojo Loop Constructs do you use?

Obviously everyone uses

For counter [As datatype] = start To | DownTo end [Step value]
Next

and most likely

While condition
Wend

but how many use these (and do you prefer any over While/Wend)?

Do
Loop

or

Do Until Condtion
Loop

or my least favorite

Do
Loop Until Conditon

are there any other (excluding For Each) that I missed?
Am trying to insure my Swift translator supports the majority of terms. The problem I would have with the last two, is the Swift equivalent has the condition on the “loop” statement… meaning I’d have to do a look ahead to determine where that is in a possiblly nested structure.

Using for and while. Found only a couple of loops.

first two for me, I can not ever remember using do-loop ever in any language I have used.

And oddly enough in XOjo

Do Until Condition
Loop Until Condiiton

:slight_smile:

The only one that matters is Loop Until The other versions of Do are just odd…

I often use

Do
.
.
Loop Until

As it’s the opposite of Do While, since it runs the loop at least once.

Oddly I almost never use Do - either in he Do While or Do until forms :slight_smile:

Maybe it’s my pascal upbringing; do/loop feels a bit like begin/end. I like it.

It depends whether you want the loop to be guaranteed to execute once or nonce if the condition attached computes to FALSE initially.

The old FORTRAN DO loop always ran at least once. Note: I haven’t used FORTRAN since 1978.

I just made that up.

:stuck_out_tongue:


Break

Do Until False
  
  System.debuglog "jello world"
  
Loop Until True

break

yes this compiles and runs and does the debuglog once :slight_smile:

I’ve never encountered another language that let you use both forms on the same loop

All For’s, all Do’s, I hate “While” because I hate “Wend” instead of “End [While]”.

1 Like

Agreed. Hate the look of “WEnd”

I also would prefer that DO was like:

Do Until | While <expression>
<statements>
End [Do]

Do
<statements>
End [Do] When <expression>

Better consistency

It’s BASIC thing… But I would have no problem if one could also use End While.

-Karen

“Was” a Basic thing. Now Dim is going dead and Var is coming in, so Xojo is changing, and selling itself as something “not BASIC”, and could fix such inconsistencies on the way.

something something something compiler guy … something

1 Like

I am not a big fan of DO/LOOP in any of its variations ( I prefer FOR/NEXT, WHILE/WEND and only use DO/LOOP when its exit conditon is not known)

While doing research for my BASIC to SWIFT translator I had thought that SWIFT had multiple loop constructs and turns out I was mistaken

  • FOR/NEXT … yup… got that one
  • WHILE/WEND … yup… got that one too
    but
  • DO/LOOP
  • DO UNTIL x/LOOP
  • DO / LOOP UNTIL x
    it actually has none of those… the closest it seems to have it
repeat
...something
} while condition

which I guess the BASIC version would be

DO
...something
LOOP UNTIL NOT(condition)

Basically I am trying to figure out how to translate

DO UNTIL condtion
...something
LOOP

and

DO
...something
LOOP UNTIL condtion

into the proper Swift “repeat” syntax… and my head is hurting :frowning:

DO UNTIL condtion
...something
LOOP

could turn into

while Not condition
...something
LOOP
DO
...something
LOOP UNTIL condtion

could turn into

repeat
...something
} while not condition

no ?

Yeah… that might work. I can translate the first situation on the fly without needing to look ahead… the 2nd might take a bit more as it needs to know if the DO needs to change to REPEAT… as it would be left as DO, if the “loop” had no condition (ie. infinitie)

yeah I can see the difficulty … short of creating a full abstract syntax tree that represents the code that you could then do various transforms on I dunno how else you do it

line by line may only get so far

Well I have a plan… its rather “brute force”… but basically entails building a dictionary of where every DO and LOOP statement is ( there is now a stack structure that insures that every loop structure has a proper ending structure etc)… then once it knows where the start and end of each loop resides it can analyze to determine which of the syntax structures it needs to be transformed to.

Another thing that needs to be done, is for the EXIT command, Swift may need to have LABELS inserted to support the “named break” structure… this same dictionary will support the ability to do this as well