Summary
- The order in which the program's statements are executed is called the flow of control.
- All programming languages support three control flow structures namely
- In sequential programming, the set of instructions or code is executed in a linear fashion.
- The selective structure consists of a test for condition followed by alternative paths that the program can follow. if, if-else, if -else-if, switch-case statements come under the selective control structure.
- The if-else Statement can be used to select one of the two mutually exclusive courses of action in a program. The body of the statements following the if statement is executed when the expression is true. When the expression is false and an else is included with the if, the body of the statements following the else is executed.
- The switch Statement controls the selection of one body of statements to be executed based upon the value of a case selector expression whose value equals the evaluated expression in the switch statement.
- The process of executing the sequence of instructions over and over again, each time using different data, is called iteration. The statements that permit C language to perform iteration are while, for and do-while Statements.
- The break Statement causes an immediate exit from the control statement in which it appears.
- The continue statement transfers program control to the place in the program such that the next iteration of the loop begins.
- The goto statement transfers control to the C statement that follows the label designated in the goto statement.
Review Questions
- What do you mean by row of control in programming languages:
- Explain the selective control flow structure with examples.
- How does the break statement differ from continue statement?
- It is not advisable to use goto statements in programs. State the reason.
- Explain the C iterative structures.
Sample Questions
- Write a program that displays the menu.
- Addition
- Division
- Subtraction
- Multiplication
Using two operands, the above mentioned functions should be performed using switch-case construct
- Write a program to check whether the given year is a leap year or not.
- Using for loop write a program to calculate the Factorial of a given number.
- Write a program to calculate the Fibonacci series
- Write a program to generate Prime numbers.