Control Statements
Control Statements
CONTROL STATEMENTS
4.0 Objectives
4.1 Introduction
4.2 The If Statement
4.2.1 The simple if statement
4.2.2 If-else statement
4.2.3 Nested-if statement
4.2.4 The if-else ladder
4.2.5 Use of logical operation with if statement
4.2.6 Hierarchy of logical operators
4.3 The switch Statement
4.4 The conditional Operator
4.5 The goto Statement
4.6 Summary
4.7 Check Your Progress - Answers
4.8 Questions for Self - Study
4.9 Suggested Readings
4.0 OBJECTIVES
Friends, After studying this chapter you will be able
• explain what to do in programming situations involving branching depending upon
certain conditions
• discuss the control statements in C for this purpose which are : if, if-else, switch,
conditional operator and goto.
• state additional features like nested ifs, the if-else ladder
• be able to make use of logical operators with if statements for more structured
programming
• develop a number of programs using these various control statements.
4.1 INTRODUCTION
Decision Control:
While writing programs, it is often necessary to change the order of execution
of depending upon certain conditions. It is also required to execute an instruction or
a set of instructions until a specific condition is met. Thus, it is necessary to take
decisions and depending upon the result of the decision execute appropriate statements
i.e. we are required to execute a set of instructions in a particular situation and an
entirely different set of instructions in other situations.
The C language has the following decision making instructions :
- if statement
- switch statement
- conditional operator statement
- goto statement
This chapter will discuss in detail all the above control statements available in
C one by one starting with the simple if and progressing to more complex structures
Control Statements / 73