Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 6: Making Decisions with Branches

Chapter 6

Making Decisions with Branches

The simplest programs consist of one or more instructions or lines of code that the computer follows sequentially, one after another. While such sequential ordering forms the basis for programming, programs need greater flexibility to make decisions depending on the current situation.

A branch provides the computer with a choice of two or more different sets of instructions to follow. The simplest type of branch provides two choices, but there's no theoretical limit to the number of branches a program can have. A complicated program may need to make hundreds or even thousands of possible decisions.

Computers decide which choice, or branch, to follow based entirely on a certain condition, known as a Boolean condition or expression. In real life, people use Boolean expressions all the time to make decisions.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial