Control Statements
  • Introduction
  • Types of Control Statements
    • Decision Making (Selecting or Branching or conditional) Statement
      • IF Statement
      • IF_ELSE Statement
      • NESTED IF_ELSE Statement
      • LADDER IF_ELSE Statement
      • SWITCH Statement
      • NESTED SWITCH Statement
    • Iterative( Repetitive or Looping) Statement
      • FOR loop
      • While loop
      • DO_WHILE loop
    • Breaking(Jumping) Statement
      • BREAK
      • CONTINUE
      • GOTO
      • RETURN
  • Pattern printing programs
  • Loop Comparison
Assignment Set
  1. Discuss the problems of programming with switch logic.
  2. Differentiate between else … if ladder and switch statements.
  3. Differentiate between entry and exit controlled loop.
  4. Why do we need break and continue statement?
Board Exam Theory Questions
  1. Compare if-else-if ladder and switch construct with example and flowchart. [5] [2074]
  2. Why do we need control statements in computer programs? Differentiate between do while and for statements. [2+2] [2074]
  3. Explain relational and logical operators. [4] [2073]
  4. Why do we need control statements? Compare switch and if-else-if ladder with example. [4] [2073]
  5. Write a C program to display all characters between a given ranges. [6] [2073]
  6. What are the purpose of the continue statement? Within which control statements can continue statement be included? Compare with the break statement. [1+2+2] [2072]
  7. How is the switch statement used in decision making? Explain with a suitable example. [4] [2072]
  8. Write the difference between do and do... while loop and write the program “to find whether a year is leap or not”. [3+7] [2071]
  9. What are control statements? Illustrate nested IF statement with its flowchart. [2+2] [2071]
  10. Explain important of break and default statement in switch statements. [3] [2070]
  11. Distinguish between break and continue statement with example. [4] [2070]
  12. What is the importance of control structure in programming? Compare if – else – if ladder and switch construct. Which is better? [1+3] [2069]
  13. Write a syntax used in C programming language for the followings: [2x2] [2067]
    i. While
    ii. If.. else
  14. State the difference between if statement and switch statement. [2067]
  15. Draw a flowchart of break and continue statement and explain their differences. [2067]
  16. Explain ‘nested for’ and ‘do while’ loops with examples. [2064]
  17. Differentiate between break and continue statement with examples and flowchart. [5] [2063]
  18. Draw the flow chart of for loop, while loop and do-while loop along with their syntax. [3] [2062]*
  19. Draw the flow chart of while statement and explain how it is different from for loop. [4] [2061]
  20. Explain in detail about break and continue statement. [3] [2061]
  21. Explain along with flowchart how do while loop differs from while loop. [4] [2061]
  22. Draw the flowchart of for statement and explain how it works. [1+2] [2060]
  23. What is the purpose of switch statement? Explain with example. [3] [2059]
  24. How does “for ” statement differ from “while and do while” statement? Explain. [4] [2059]
  25. Describe how switch statement works. What are the restrictions on case labels. [3+1] [2058]
  26. Differentiate between conditional operator and if-else statement. [2] [2068]
  27. Write a syntax in C-programming with example of the following. Do... while [2] [2068]

Control Statement

The control statement are used to create special program features such as Decision making statement, Iterative statement and Jumping statement.



Decision Making Statement / Selective / Branching Statement

if

The "if" statement is a powerful decision making statement which is used to execute a block of statement base on whether the given test condition is true or false.
If the condition is true, the block of statement will be executed, otherwise it will be skipped.

if else

The "if else" statement is simply an extension of if statement which is used to execute the true block statement or false block statement depending upon the test condition.

nested if else

The "nested if else" statement is simply an extension of if else statement which is obtained by using an if else decision statement within another if else decision statement.

if else ladder

The "if else ladder" helps user decide from among multiple options which is executed from the top down. As soon as one of the conditions is true, the statement associated with that if is executed, and the rest of the else-if ladder is bypassed. If none of the conditions is ture, then the final else statement will be execute.

Switch statement

Switch statement allows a programmer to choose a particular block of statements from several blocks of statements.



Iterative Statement

Iterative statement or loop statement in C program causes a section of program to be executed repeatedly until some logical condition has been satisfied is known as loop.

for loop

The for loop is used to execute a statement for fixed number of times.



while loop

  • The while loop is used to execute a statement for unknown number of times.
  • The while loop is called top tested loop as the test expression is at the beginning of the program.
  • The body of the loop is executed only if the test condition is true.


do - while loop

  • The do while loop is used when one is sure about the test condition
  • The do while loop is also called botton tested loop as the test expression is at the bottom of the loop.
  • The body of the loop is executed at least once even if the test condition is false.


Entry Control loop Exit Control loop
Entry Control loop checks condition first and then body of the loop will be executed. The exit control loop first executes the body of the loop and checks condition at last.
The body of the loop may or may not be executed at all. The body of the loop will be executed at least once because the condition is checked at last.
for, while are an example of an entry control loop. Do... while is an example of an exit control loop.


BREAK

  • The break statement is used to terminate or to exit or to jump out of the loop or switch statements.
  • It can be used within a for, while, do-while or switch statement.


CONTINUE

  • Whenever the continue statement is encountered the remaining portion of the loop after the continue is skipped out and proceeds directly to the next pass of the loop.
  • The loop won't be terminated when a continue statement is encountered.


GOTO

  • The goto statement alters the normal sequence of program execution by transferring control to some other parts of program.
  • Basically it is used for jumping, to any part of the program from any position.


EXIT() FUNCTION

  • The exit function is expecially used to terminate or to exit from the entire loop and program as a whole.
  • Thus, whenever the exit() function is encountered, the program execution is brought to an end.
  • It can be included at any position in the program body.
Programming Set
  1. Write a program that reads a number and identifies whether the given number is even orodd.
  2. Write a program to find the largest number among two numbers.
  3. Write a program to read the mark of a subject and prints the equivalent grade.
  4. Write a program to read a sentence and counts the total number of character (excluding space) using while loop.
  5. Write a program to generate Fibonacci number using do while loop.
  6. Write a program to read number and identifies whether the given number is a prime number or not.
  7. Write a program to identify whether the given number is a perfect number or not. 28 is a perfect number.
  8. Write a program to calculate the factorial of a given number.

DECISION MAKING / SELECTIVE / BRANCHING STATEMENT

  • if
  • if else
  • nested if else
  • if else ladder
if
if else
nested if else
if else ladder
Switch

LOOPING / ITERATION / REPETITIVE STATEMENT

  • for loop
  • nested for loop
  • for loop with break
  • while loop
  • continue with loop
for loop
Nested for loop
For loop with break;
For loop with continue;
while loop
do while loop
goto
Web hosting by Somee.com