Syntax:
DO [ WHILE Condition ] . .. [ BREAK | CONTINUE ] . .. LOOP [ UNTIL Condition ]
With DO… LOOP a series of statements is repeated until the initial condition remains true or until the last condition becomes true. If neither WHILE nor UNTIL are used in the control structure, this results in an infinite loop that can only be exited using the BREAK statement. If the break statement itself is missing, there is an infinite loop that you can no longer stop.
The following table shows the individual parts of the control structure Do..Loop:
Part | Description |
---|---|
Do | The first statement in the control structure. |
While | If While is used, the statements in the loop body are only executed if the subsequent Boolean expression is TRUE. |
Until | If Until is used, the instructions in the loop body are only executed until the subsequent Boolean expression is TRUE. |
Condition | Boolean expressions |
Break | Jump from the control structure Do..Loop. The execution of the program is started with the next line after the control structure Do..Loop continued. |
Continue | All statements after Continue are ignored and a new run starts. |
Loop | The last statement in the control structure. |
Table 10.3.6.1.1.1: Description of the elements of Do..Loop
Example 1
Public Sub LVW2C(lv As ListView, c As Collection) ' ListView To Collection If lv.Count > 0 Then c.Clear lv.MoveFirst() DO c[lv.Item.Key] = lv.Item.Text LOOP UNTIL lv.MoveNext() Else Message.Info("The channel list is empty!") c.Clear Return Endif End
Example 2
Private Sub Variante_3(iAnfang As Integer, iEnde As Integer) Dim iPartialsumme As Integer = 0 Dim iSummand As Integer = iAnfang DO WHILE (iSummand < iEnde + 1) iPartialsumme = iPartialsumme + iSummand If IsIntegerRange(iPartialsumme) = False And b = False Then txtPartialsumme.Text = "Error sum " & String.Chr(8713) & " INTEGER" Return Endif Inc iSummand LOOP txtPartialsumme.Text = Str(iPartialsumme) ' Alternative Variante 3.2: ' WHILE (iSummand < iEndzahl + 1) ' iPartialsumme = iPartialsumme + iSummand ' INC iSummand ' WEND ' While End ' tboxPartialsumme.Text = Str(iPartialsumme) End ' Variante_3 - Kontrollstruktur DO..WHILE..LOOP
In the control structure DO… LOOP There are many instructions (While, Until, Break, Continue) that you have already got to know. Based on' http://de.wikipedia.org/wiki/Syntactic_Sugar',' syntactic sugar' means syntax extensions in a programming language. These extensions are alternative spellings that do not extend the functionality of a programming language not. Syntactic sugar can be traced back to elementary instructions of the language by changing the diction, because
Do While bedingung ' sequence of instructions Loop
is a long version of While-Wend; just like
Do ' sequence of instructions Loop Until bedingung
as a long version of Repeat-Until. Also
Do ' sequence of instructions Loop
produces an endless loop like
While True ' Sequence of instructions Wend.
This means, however, that you can only use the control structure DO..LOOP, which is classified as “syntactic sugar” in Gambas. In example 2, the procedure with alternative 3.2 was demonstrated.