User Tools

Site Tools


k10:k10.3:k10.3.3:start

10.3.3 REPEAT UNTIL control structure

The REPEAT UNTIL control structure is also a form of loop control structure.

10.3.3.1 Syntax

Syntax for the REPEAT UNTIL control structure:

REPEAT 
  <Instruction(s)> 
UNTIL Expression

10.3.3.2 Notes on syntax

  • The loop is repeated until expression is true.
  • Since the check of the termination condition takes place at the end of the REPEAT-UNTIL control structure, the statement sequence is executed at least once.

10.3.3.3 Example 1

The example refers to a project in chapter? 18.12 ListContainer. With the statement in the fourth line of the procedure below, the HTTP client is sent into the track to load data from the specified server. Afterwards, the system waits in the waiting loop until the download is complete and the HTTP client is (again) inactive:

Public Sub cmbFeedSource_Click() 
  ListContainer.Clear 
  myHttpClient.URL = Feeds[cmbFeedSource.Index] 
  myHttpClient.Get 
  Repeat 
    Wait 0.01 
  Until myHttpClient.Status = Net.Inactive 
' Automatically select the first feed - if available 
  If ListContainer.Count Then ListContainer.Index = 0 
End ' cmbFeedSource_Click()

10.3.3.4 Example 2

The REPEAT-UNTIL control structure uses the approximate determination of a zero point of a function f (x) according to the secant approximation method. Incorrect start values for the two arguments xa and xe are recognized and displayed. It should be ensured that the function has exactly one zero point in the completed interval[xa | xe].

Secant method (Numerik)

Figure 10.3.3.4.1: Proximity method with adjustable accuracy

The source text is completely specified:

' Gambas class file
 
Public Sub Form_Open()
  FMain.Center
  FMain.Resizable = False
End ' Form_Open()
 
Public Function f(x_wert As Float) As Float        
    Return (x_wert * x_wert) - 4    
End ' Function f(x_wert As Float) 
 
Public Sub btnNullstelleBerechnenUndAusgeben_Click()
  Dim iCount As Integer
  Dim x1 As Float         ' Left interval limit
  Dim x2 As Float         ' Right interval limit
  Dim fEpsilon As Float   ' Stop criterion
  Dim y1, y2, fNullstelle, fDifferenzenquotient As Float
 
  x1 = CFloat(txb_x1.Text)
  x2 = CFloat(txb_x2.Text)
  fEpsilon = CFloat(txb_epsilon.Text)
  If f(x1) * f(x2) > 0 Then
     Message.Error("The start values x1 and x2 are not allowed!")
     txb_x2.SetFocus
     Return
  Endif ' f(x1) * f(x2) > 0
  txaTabelle.Clear
 
  Repeat
    y1 = f(x1)
    y2 = f(x2)
    fDifferenzenquotient = (x2 - x1) / (y2 - y1)
    fNullstelle = x1 - (y1 * fDifferenzenquotient)
    txaTabelle.Text = txaTabelle.Text & " " & Str(iCount) & Chr$(9) & Format$(fNullstelle, "0.0000000") 
                      & Chr$(9) & "   " & Str(f(fNullstelle)) & Chr$(10)
      If f(x1) * f(fNullstelle) > 0 Then
        x1 = fNullstelle
      Else
        x2 = fNullstelle
      Endif
    Inc (iCount)
  Until Abs(f(fNullstelle)) < fEpsilon
 
End ' btnNullstelleBerechnenUndAusgeben_Click()
 
Public Sub xGroup_Change()
  txaTabelle.Clear  
End ' xGroup_Change()

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k10/k10.3/k10.3.3/start.txt · Last modified: 23.09.2023 by honsek

Page Tools