Two ways to plan conditional execution

Let's use our greeting program as an example.

The first step is to make sure we understand the external description -- what you are trying to get the computer to do.

The program displays either a nice or nasty message. The messages is determined by what the user enters in the small textbox. If it starts with "n" or "N," a nasty message is displayed. If not, the program displays a nice message.

Before you try programming this in VB, you might find it helpful to sketch a flowchart or to write the program in psuedo code.

The flowchart is shown here. It starts with the test of the first letter. Then, different instructions are executed depending upon that first letter.
Psuedo code is another planning tool that some people find helpful.

Since there are two alternative paths in this program, we will use an if...then...else statement, which has this syntax:

If <Boolean expression> then
   execute if the expression is true
Else
   execute if the expression is false
End If
The psuedo code is shown here. As you see it is a mixture of VB syntax and English.
If the first letter is "n" or "N" then
   Display a nasty message
Else
   Display a nice message
End If


Disclaimer: The views and opinions expressed on unofficial pages of California State University, Dominguez Hills faculty, staff or students are strictly those of the page authors. The content of these pages has not been reviewed or approved by California State University, Dominguez Hills.