User Tools

Site Tools


k10:start

10.0 Control structures

Every task or problem - as a task with a higher level of requirements - whose solution can be described by algorithms, can in principle be solved with the help of the thinking tool computer. This makes the direct correlation between the algorithm and the computer program obvious, which has already been clearly highlighted in chapters 4.5 and 4.6. For the program design, the algorithms for the most important procedures must be available in a suitable form of description - either as text or in another suitable form (natural language - text, pseudo code, structure diagram or also Nassi-Shneiderman diagram) - whereby the representation form (notation) is adapted to the respective task.

When displaying algorithms, you will notice that each algorithm is composed of a few structure elements. These structures are called control structures because they are used to control and control complex (program) sequences. The following control structures are described in this chapter:

  • Linear instruction sequence (sequence)
  • Selection (case discrimination or selection)
  • Repeat (loop or loop)
  • Special control structures

10.0.1 Selection - Case discrimination or selection

  • One-sided selection IF… THEN… ENDIF
  • Two-sided selection 1 IIF (selector, A, B)
  • Two-sided selection 2 IF… THEN… ELSE… ENDIF
  • Multi-selection 1 IF…. THEN…[ ELSE IF.. .. ELSE IF] … ENDIF
  • Multiple selection 2 SELECT CASE… END SELECT
  • Multi-selection 3 Choose (…)

10.0.2 Repeat - Loop

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

10.0.3 Special control structures

  • RETURN
  • STOP
  • QUIT
  • WITH… END WITH
  • GOTO
  • ON GOTO
  • GOSUB
  • ON GOSUB
  • Application.BUSY

10.0.4 Example

The following section introduces an excerpt from the source code of a real project, in which some of the above control structures (For Each..In..Next, For..To..Step..Next, Select.Case, Recursion, If..Then..Else..Endif) the program flow is controlled and controlled in one procedure:

Public Sub ParseNode(Node As XmlNode) 
 
  Dim xmlNode, xmlAttribute As XmlNode 
  Dim hFeed As FeedItem 
  Dim iCount As Integer 
 
  FOR EACH xmlNode IN Node.Children 
    IF xmlNode.Name = "item" THEN 
       hFeed = New FeedItem(ListContainer.Count + 1, ListContainer) 
       FOR iCount = 0 TO xmlNode.Children.Max STEP 1
         xmlAttribute = xmlNode.Children[iCount] 
         SELECT CASE xmlAttribute.Name 
           CASE "title" 
             hFeed.FeedTitle = xmlAttribute.Value 
           CASE "description" 
             hFeed.Description = xmlAttribute.Value 
           CASE "link" 
             hFeed.Link = xmlAttribute.Value 
         END SELECT ' xmlAttribute.Name 
       NEXT ' iCount 
    ELSE 
       IF xmlNode.Children.Count > 0 THEN ParseNode(xmlNode) ' Recursive call!
    ENDIF ' xmlNode.Name = "item" ? 
  NEXT ' Each xmlNode 
 
End ' ParseNode(...) 

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

Page Tools