I l @ ve RuBoard |
You will learn about the following in this chapter:
Keywords
for while do while
Operators
< > >= <= != == += *= -= /= %=
In this chapter, you learn about C's three loop structures: while , for , and do while . You use relational operators to construct expressions to control these loops, and you learn about several other operators, too. Arrays, which are often used with loops , are introduced. Finally, you take a first look at writing functions that have return values.
Powerful, intelligent , versatile, and useful! Most of us wouldn't mind being described that way. We're not going to tell you how to earn these accolades for yourself, but, with the help of C, your programs can earn them. The trick is controlling the flow of a program. According to computer science (which is the science of computers and not science by computers yet), a good language should provide these three forms of program flow:
Executing a sequence of statements.
Repeating a sequence of statements until some condition is met (looping).
Using a test to decide between alternative sequences (branching).
The first form you know well; all the previous programs have consisted of a sequence of statements. The while loop is one example of the second form. In this chapter, you'll take a closer look at the while loop along with two other loop structures: for and do while . The final form, choosing between different possible courses of action, makes a program much more "intelligent" and increases the usefulness of a computer enormously. Sadly, you'll have to wait a chapter before being entrusted with such power. Let's begin by reviewing the while loop.
I l @ ve RuBoard |