Fifth Chapter Lesson-14 Conditional Control Statements in C language

At the end of this lesson-

  • 1. You will be able to explain control statement. 
  • 2. You will be able to explain different control statements. 
  • 3. You will be able to explain conditional control statement details. 
  • 4. You will be able to write program using conditional control statement. 

 

Control statements: A control statement is a statement that determines whether other statements will be executed. Control statements control the flow of program. They make it possible to make decisions, to perform tasks repeatedly or to jump from one section of code to another.

Control Statements are:

  • 1. Conditional Control Statements / Decision control statements
  • 2. Loop Control Statements
  • 3. Jumping Control Statements

 

Decision control statements: In decision control statements, group of statements are executed when condition is true.  If condition is false, then else part statements are executed. Decision control statements are:

  • if statements
  • if-else statements
  • else if statements
  • nested if-else statements
  • switch statements

 

if statements: It is used to decide whether a certain statement or block of statements will be executed or not. The ‘if’ statement evaluates the condition inside the parenthesis. If the condition is true statement(s) inside the body of ‘if’ is executed. If the condition is false statement(s) inside the body of ‘if’ is skipped from execution. Syntax of ‘If’ statement:

Program for determining a number is positive.

 

if-else statements: In if-else control statement, group of statements are executed when condition is true. If condition is false, then else part statements are executed. There is no condition for else statement. Syntax of ‘if-else’ statement:

Program for determining a number is whether positive or negative.

 

else if statements: The else..if statement is useful when you need to check multiple conditions within the program, nesting of if-else blocks can be avoided using else..if statement. Syntax of else..if statement:

 

Program for determining a number is whether zero, positive or negative.

 

nested if-else statements: It is possible to include if-else statement(s) inside the body of another if-else statement. Syntax of nested if-else:

 

Program for determining a year whether leap year or not.

 

switch statements: The switch statement is a multiway branch statement. A switch statement tests the value of a variable and compares it with multiple cases. Once the case match is found, a block of statements associated with that particular case is executed. If a case match is found, then the default statement is executed, and the control goes out of the switch block. Syntax of switch statement:

 

The following rules apply to a switch statement: 

  • 1. Case constants must be either char(‘A’, ‘B’../ ‘a’,’b’…/’+’,’-‘ , etc) or int(1,2,3 – -) type. If it is char type it should be enclosed with single quotation(‘ ‘).
  • 2. Case constants must be unique.
  • 3. Case constants must end with a colon ( : ).
  • 4. A break keyword must be present in each case.
  • 5. It can be same code block for multiple cases.
  • 6. There can be only one default label.

 

Example-1: Program using switch statement that can perform addition, subtraction, multiplication, division.

 

Example-2: Write a program using switch statement to determine a letter is whether vowel or consonant.

 

Lesson Evaluation-

Knowledge Based Questions:

  • a. What is control statement?
  • a. What is conditional control statement?
  • a. What is switch statement?

Comprehension Based Questions:

  • a. When switch statement is more convenient to use?

Creative Questions:

Multiple Choice Questions:

 


Written by,

Leave a Reply

Your email address will not be published. Required fields are marked *