ABSTRACT

As noted in the earlier chapters, the computer executes the program statements sequentially, one after the other in their chronological order, just as water flows in a waterfall. But decision making involves choosing between available alternatives, which require skipping the chronological path and jumping to another statement that may not be the next immediate statement. Control statements facilitate this transfer of execution to a desired statement. To be able to program a decision-making capability into our programs, we need to master the control statements. The control statements, namely the goto, if-then-else, and switch-case, are enumerated and discussed along with their utility and limitations. Then the loops, which are a variant of control statements that help us to execute a set of statements iteratively based on a condition, are enumerated and explained. Loops could be counting-based finite loops or a condition-based loops. Either way, every loop must have a provision for exiting the loop. Counting-based For-Next loops and condition-based loops are discussed in detail. Condition-based loops generally use the WHILE keyword. The condition may be at the top of the loop or at the bottom of the loop. Both are discussed in this chapter. This chapter goes on to discuss the precautions to be taken while writing the loop statements, as well as the best practices in writing the loops.