O'Reilly logo

Beginning Visual Basic 2015 by Bryan Newsome

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4 Controlling the Flow

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • How to use the If statement
  • How to use Select Case
  • How to use For loops and Do loops

WROX.COM CODE DOWNLOADS FOR THIS CHAPTER

The wrox.com code downloads for this chapter are found at www.wrox.com/begvisualbasic2015 on the Download Code tab. The code is in the 092117 C04.zip download and individually named according to the names given throughout the chapter.

In Chapter 3, you learned about algorithms and their role in programming. In this chapter, you will look at how you can control the flow through your algorithms so that you can make decisions like “If X is the case, go and do A; otherwise do B.” This ability to make decisions is known as branching. You’ll also see how you can repeat a section of code (a process known as looping) a specified number of times, or while a certain condition applies.

MAKING DECISIONS

Algorithms often include decisions. It’s this decision-making ability that makes computers do what they do so well. When you’re writing code, you make two kinds of decisions. The first kind is used to find out what part of an algorithm you’re currently working on or to cope with problems. For example, imagine that you have a list of 10 people and need to write a piece of code to send an email to each of them. To do this, after sending each email, you ask, “Have I finished?” If so, you quit the algorithm; otherwise, you get the next person in the list. As another example, you might need to open a file, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required