Presentation on theme: "Selection Flow Charts If statements. Flow of Control The flow of control is a concept we’ve already encountered. The concept of control relates to the."— Presentation transcript:
Selection Flow Charts If statements
Flow of Control The flow of control is a concept we’ve already encountered. The concept of control relates to the machine level in which a single instruction controls the behaviour of the CPU. The flow of control describes how control passes from one instruction to the next.
Flow Charts A handy way to map the logic of a program is the Flow Chart. Flow Charts use specific shapes to represent computer actions and join these together with arrows to show the flow of control. Each type of action is represented by a specific shape.
Flow Chart Symbols There is no single standard for flow chart shapes, but there is a widely used core set. The start and end of a program are represented by lozenges, ovals or rounded rectangles. The flow of control is represented by arrows. –An arrow coming from one symbol and ending at another symbol represents that control passes in the direction of the arrow.
Flow Chart Symbols Processing steps are represented by rectangles. Input/Output are represented by a variety of shapes, including parallelograms. –Some programmers use different symbols for input than for output. –Some even use different symbols for different types of input or output. (printer, screen, speaker, etc.)
Charting the Flow of Control Flow charts help visualise the flow of control. The simplest form is sequence. Note the use of alternate symbols for I/O. Declare vars for input and result get input produce result from input show result
Flow Chart Symbols Frequently, a program will need alternative logic paths, one for some data, and another for other data. In a flow chart a branch in the logic path is represented by a diamond.
Flow Chart Symbols A condition (or decision) is represented by a diamond (rhombus). These typically contain a Yes/No question or True/False test. This symbol is unique in that it has two arrows coming from it: –one corresponding to Yes (or True) –and one corresponding to No (or False).
Branches in VB A branch in the logic of a VB program is created by the If statement. If Then … End If
If Then If condition Then ‘body End If Condition True False Process
If …Then…Else If condition Then ‘body Else ‘body End If Condition TrueFalse Process
ElseIf If condition Then ‘body ElseIf condition Then ‘body Else ‘body End If Condition TrueFalse Process Condition TrueFalse Process
Else If If condition Then ‘body Else If condition Then ‘body Else ‘body End If Condition TrueFalse Process Condition TrueFalse Process
Nested Ifs If condition Then ‘body Else ‘body End If Else If condition Then ‘body Else ‘body End If Condition False Condition True Condition Process False True