Table of Contents

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:

10.0.1 Selection - Case discrimination or selection

10.0.2 Repeat - Loop

10.0.3 Special control structures

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