Page 9 - Touchcode_C8_Flipbook
P. 9
1 CONDITIONALS IN DETAILS
Learning Outcomes
Introduction Types of Control Structures
Understanding IF-ELSE and ELSE-IF Statements Logical Operators
Relational Operators Precedence of Logical Operators
INTRODUCTION
In programming, the flow of the program is a very important aspect. If controlled correctly,
a program can be made highly efficient. In this chapter, you are going to learn about the
flow of program.
TYPES OF CONTROL STRUCTURES
Control structure is a coding construct that is used to decide the flow of a program based
on the parameters given to it. Usually, a control structure accepts and analyses a variable to
make a decision on which direction to proceed. So, the control structure is a basic decision-
making process in computing.
The three basic types of control structures are:
Sequential: Statements in a program are executed sequentially or step-by-step in an
order in which the instructions are written.
Selection/Conditional: It is used to test a condition in a program. It takes decision to
execute one statement/operation over another statement/operation depending on the
condition.
Iteration: It executes set of statements for a certain number of times till the given
condition is true. Example: Loops
On the basis of the above three control structures, programming has derived many types
of control statements to suit different needs.
UNDERSTANDING IF-ELSE AND ELSE-IF STATEMENTS
Every day, you take many decisions depending on the situation. For example, if you are
given a number and you need to check if the number is even or odd, you will check this by
dividing the number with 2. If the remainder is 1, the number is odd and if the remainder is
0, then the number is even.
Conditionals in Details 7

