Structured Programming

This article describes different ways of what is called as structured programming.

At the very simplest level programming consists of issuing a sequence of commands to a computer to achieve an objective. Once you understand the concept of structured programming and how a particular programming language implements them you can then write a program in that language.

Sequences of Instructions

Here the program flows from one step to the next in strict sequence.

not available

Example: A sample code for adding numbers would look something like the following.Start AddNumbers
    Sum=Number1 + Number2

Conditional Branching

This is the most used part of structured programming. Here the program reaches a decision point; if the result of the test is true then the program performs instructions in Path 1, and if false it performs the actions in Path 2. This is also known as a conditional construct because the program flow is dependent on the result of a test condition.

not available

Example: A sample code for identifying the higher number of the two would look something like the following.Start GreaterNumber
    If Number1 > Number2 Then
        Message "Number1 is greater than Number2"
        Message "Number2 is greater than Number1"
    End If

Conditional Looping

In this construct the program steps are repeated continuously until some test condition is reached, at which point control then flows past the loop into the next piece of program logic.

not available

Example: A sample code for adding numbers from 1 to 100 would look something like the followingStart SumOfNumbers
    Loop Till CurrentNumber > 100
        SumOfNumbers= SumOfNumbers + CurrentNumber
        CurrentNumber= CurrentNumber + 1
    End Loop

Shared Procedure

Here the program performs an identical sequence of actions several times. For convenience these common actions are placed in a procedure, which is a kind of mini-program and can be executed from within the main program. Such procedures area also called sub-routines or functions. This is the most important part of structured programming as it helps reduces code repetitions.

not available

Example: A sample code for checking if a file exists would look something like the following. Notice that Check1 and Check2 both use the shared procedure FileCheck.Start Check1
    FileCheck Filename

Start FileCheck (File)
    … Code to check if file in present on the system
    If FileExists then
        Message "File is present"
        Message "File not found"
    End if

Start Check2
    FileCheck Filename2
Don't worry if all this seems a bit confusing; read it for a second time and move on. Things will get clearer as you learn more. And remember the sample codes given above are only for illustrative purposes. The actual syntax of coding differs for every programming language, but the fundamental structures remain the same.

Back to Visual Basic for Beginners