Introduction to Problem Solving and Control Statements in Visual Basic 2010
- 4.1 Introduction
- 4.2 Algorithms
- 4.3 Pseudocode
- 4.4 Control Structures
- 4.5 If...Then Selection Statement
- 4.6 If...Then...Else Selection Statement
- 4.7 Nested If...Then...Else Statements
- 4.8 Repetition Statements
- 4.9 Compound Assignment Operators
- 4.10 Formulating Algorithms: Counter-Controlled Repetition
- 4.11 Formulating Algorithms: Nested Control Statements
- 4.12 Using the Debugger: Locating a Logic Error
- 4.13 Wrap-Up
- Summary
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Quick Quiz
- Exercises
- Making a Difference Exercises
- Let's all move one place on.
- —Lewis Carroll
- The wheel is come full circle.
- —William Shakespeare
- How many apples fell on Newton's head before he took the hint?
- —Robert Frost
4.1 Introduction
Before writing a program to solve a problem, you should have a thorough understanding of the problem and a carefully planned approach. When writing a program, it's also important to know the available building blocks and to use proven program-construction principles. In this chapter and the next, we present the theory and principles of structured programming with control statements. We introduce the If...Then, If...Then...Else, Do While...Loop, While...End While and Do Until...Loop statements—five of the building blocks that allow you to specify the logic required for methods to perform their tasks. We introduce the ListBox control and use it to display and process data, such as a list of grades in a class-average program. We also demonstrate how to "stack" and "nest" control statement to solve problems. The chapter concludes with an introduction to the Visual Studio debugger. You'll learn how to view the values of variables during a program's execution, how to step through code one statement at a time and how the debugger can help you locate logic errors in your programs.