30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

100 Control Structures: Part 1 Chapter 4<br />

add grade <strong>to</strong> <strong>to</strong>tal <strong>to</strong>tal = <strong>to</strong>tal + grade<br />

add 1 <strong>to</strong> counter counter = counter + 1<br />

Fig. Fig. 4.1 4.1 Sequence structure flowchart.<br />

Perhaps the most important flowcharting symbol is the diamond symbol, alternatively<br />

referred <strong>to</strong> as the decision symbol, which indicates that a decision is <strong>to</strong> be made. We discuss<br />

the diamond symbol in Section 4.5.<br />

<strong>Visual</strong> <strong>Basic</strong> provides three types of selection structures, which we discuss in this<br />

chapter and the next. The If/Then selection structure performs (selects) an action (or<br />

sequence of actions) if a condition is true or skips the action (or sequence of actions) if the<br />

condition is false. The If/Then/Else selection structure performs an action (or sequence<br />

of actions) if a condition is true and performs a different action (or sequence of actions) if<br />

the condition is false. The Select Case structure, discussed in Chapter 5, Control Structures:<br />

Part 2, performs one of many actions (or sequences of actions), depending on the<br />

value of an expression.<br />

The If/Then structure is called a single-selection structure because it selects or<br />

ignores a single action (or a sequence of actions). The If/Then/Else structure is called a<br />

double-selection structure because it selects between two different actions (or sequences of<br />

actions). The Select Case structure is called a multiple-selection structure because it<br />

selects among many different actions or sequences of actions.<br />

<strong>Visual</strong> <strong>Basic</strong> provides seven types of repetition structures—While, Do While/<br />

Loop, Do/Loop While, Do Until/Loop, Do/Loop Until, For/Next and For<br />

Each/Next. (Repetition structures While, Do While/Loop and Do Until/Loop are<br />

covered in this chapter; Do/Loop While, Do/Loop Until, and For/Next are covered<br />

in Chapter 5, Control Structures: Part 2; and For Each/Next is covered in Chapter 7,<br />

Arrays.) The words If, Then, Else, End, Select, Case, While, Do, Until, Loop,<br />

For, Next and Each are all <strong>Visual</strong> <strong>Basic</strong> keywords (Fig. 4.2). We discuss many of <strong>Visual</strong><br />

<strong>Basic</strong>’s keywords and their respective purposes throughout this book. <strong>Visual</strong> <strong>Basic</strong> has a<br />

much larger set of keywords than most other popular programming languages.<br />

<strong>Visual</strong> <strong>Basic</strong> has 11 control structures—sequence, three types of selection and seven<br />

types of repetition. Each program is formed by combining as many of each type of control<br />

structure as is necessary. As with the sequence structure in Fig. 4.1, each control structure<br />

is flowcharted with two small circle symbols—one at the entry point <strong>to</strong> the control structure<br />

and one at the exit point.<br />

Single-entry/single-exit control structures (i.e., control structures that each have one<br />

entry point and one exit point) make it easy <strong>to</strong> build programs—the control structures are<br />

attached <strong>to</strong> one another by connecting the exit point of one control structure <strong>to</strong> the entry<br />

point of the next. This is similar <strong>to</strong> stacking building blocks, so, we call it control-structure

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!