Swift : translate Xojo DO Loops to Swift syntax

as most of you know, I have been working on a Transpiler for Swift for quite some time, and recently realized that I had totally forgotten about the DO…LOOP structure

Xojo supports 4 variations of this

DO ... LOOP
DO UNTIL <cond> ... LOOP
DO ... LOOP UNTIL <cond>
DO UNTIL <cond1> ... LOOP UNTIL <cond2>

the last is “legal” but I doubt rarely if ever used

Here is a Xojo Code Snippet

Do  //1
  Do Until a = 5 //2
    Do    // 3      
      Do Until (a=5) //4 
        // do stuff
      Loop Until (a=0) //4      
    Loop Until (a=0)  // 3           
  Loop   //2                   
Loop //1             

Here is the same expressed as Swift code after passing thru my transpiler

while (true) { //1
   while  !( a == 5) { //2
      while (true) { // 3
         while  !(( a == 5)) { //4
             // do stuff
             if !( a == 0) { break }
         } //4
         if !( a == 0) { break }
       } // 3
   } //2
} //1

Note : REPEAT could have been used in at least one place instead of WHILE, but I opt’d to use WHILE as it did not require the transpile to execute a LOOK-AHEAD method to examine the LOOP

1 Like