Chapter 4. Control structures

 

This chapter covers

  • Jumping to other pieces of code inside a program
  • Creating attractive, usable menus
  • Using For, While, and Repeat loops to create complex programs
  • Using subprograms for recursion and code reuse

Conditional statements allow your program to make decisions given rules and facts, as you now know from chapter 3. If your programs could use these decisions to jump around within their source code and execute different sections, they could become vastly more powerful. With such commands, you could create whole new classes of programs and games. You’d be able to write your own programs like the GUESS guessing game in chapter 1 that we touched on briefly again in chapters 2 and 3. With loop and jump commands, you’d be able to write a science program that simulates the solar system, repeatedly stepping the planets along their orbits around the sun until told to stop. A math program could offer a menu of possible types of equations it could help you solve, and it could use jumps to go to different parts of the program to solve that equation depending on which option the user chooses.

4.1. Labels and Goto

 
 

4.2. Menus

 
 
 
 

4.3. For, While, and Repeat

 
 
 
 

4.4. Subprograms and termination

 
 

4.5. Summary

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage