User Tools

Site Tools


k10:k10.3:start

10.3 Repetitions - Iteration

If statements or a sequence of statements must be repeated in a statement block, you can use the following selected control structures described in this chapter. In the list you will find only the short, synonymous descriptions.

The control structures are called Repeat, Iteration or Loop/.

  • FOR..TO..STEP… NEXT
  • FOR EACH..IN..NEXT
  • REPEAT…. UNTIL
  • WHILE… WEND
  • BREAK and CONTINUE
  • DO… LOOP

Example for the use of 3 different control structures (WHILE..WEND, FOR..TO..STEP..NEXT and FOR EACH..IN..NEXT) in one function:

Private Function IsPolynomial(sInput As String) As Boolean
  Dim sPattern, sTerm As String
  Dim aResult, aTmp As New String[]
  Dim iI, iJ As Integer
  Dim sExpression As String
 
  sInput = Trim(sInput)
  sInput = Replace$(sInput, Left$(Format$(0, ".0")), ".")
  aResult = Split(sInput, "+", "", True)
 
  iI = 0
  While iI < aResult.Count
    sExpression = IIf(aResult[iI] Not Begins "-", "+", "") & aResult[iI]
    aResult.Remove(iI)
    aTmp = Split(sExpression, "-", "", True)
    For iJ = 0 To aTmp.Max Step 1
      aTmp[iJ] = IIf(aTmp[iJ] Not Begins "+", "-", "") & aTmp[iJ]
    Next ' iJ
    aResult.Insert(aTmp, iI)
    iI += aTmp.Count
  Wend
 
  sPattern = "^[+-]?([0-9]+(\\.[0-9]+)?)?(x([\\^][0-9]+)?)?$"
 
  For Each sTerm In aResult
    If sTerm Not Match sPattern Then
       Return False
    Endif ' Match Pattern
  Next ' sTerm
 
  Return True
 
End

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/start.txt · Last modified: 23.09.2023 by honsek

Page Tools