COMPTER POGRAMMING AND UTILIZATION
CONTROL STRUCTURES IN ‘C’
GUIDED BY: Prof. Parin Patel
GROUP MEMBERSNAME
RAJPUT ROHANSHARMA MAULIKSINGH DEVANSHSINGH UDDESHYA
CONTENTS Introduction If Statement Simple if Statement If….else Statement Nested if Statement The Else If Ladder The Switch Statement The ?:operator The GOTO Statement The while Statement The do Statement The for Statement
INTRODUCTION DECISION MAKING In bank, if we want to withdraw money, there
should be enough bank balance. So certain actions can take place if specific conditions are satisfied. This is called decision making.
C language supports following statements for decision making capability.
1. If statement2. Switch statement3. Conditional operator statement4. Goto statement
1.IF STATEMENT The if statement is a powerful decision
making statement and is used to control the flow of execution of statements.
It is basically a two way decision statement and is used in conjuction with an expression.
General form if(expression) Statement(s);
FLOW CHART OF IF CONTROL
EXAMPLE OF IF CONTROL
2.SIMPLE IF STATEMENT General form if (test expression) { statement-block; } statement x;
FLOW CHART OF SIMPLE IF CONTROL
EXAMPLE OF SIMPLE IF CONTROL
3.IF….ELSE STATEMENT The if….else statement is an extension of the simple if
statement. General form if (test expression) { true-block statement(s) } else { false-block statement(s) } statement x
FLOW CHART OF IF….ELSE CONTROL
EXAMPLE OF IF….ELSE CONTROL
4.NESTED IF STATEMENT General form if (test condition-1) { if (test-condition-2); { statement-1; } else { statement-2; } } else { statement-3; } statement-x;
FLOW CHART OF NESTED IF STATEMENT
EXAMPLE OF NESTED IF STATEMENT
5.THE ELSE IF LADDER General form if (condition 1) statement-1; else if (condition 2) statement-2; else if (condition 3) statement-3; else if (condition n) statement-n; else default statement; statement-x;
FLOW CHART OF ELSE….IF LADDER
EXAMPLE OF ELSE….IF LADDER
6.THE SWITCH STATEMENT General form switch (expression) { case value-1: block-1 break; case value-2: block-2 breal; …………….. …………….. default: default-block break; } statement-x;
SELECTION PROCESS OF SWITCH STATEMENT
EXAMPLE OF SWITCH STATEMENT
7.THE?: OPERATOR The ?: operator is used to make two way
decision. General form conditional expression?
expression1:expression2
EXAMPLE OF ?: OPERATOR
8.THE GOTO STATEMENT In “C” language goto statement is used to jump unconditionally from one point to another in
the same program. The goto statement requires a label. General form (forward jump) goto skip; …………….. …………….. …………….. skip: statement;
(backward jump) skip: statement; …………….. …………….. …………….. goto skip;
EXAMPLE OF GOTO STATEMENT
9.THE WHILE STATEMENT The simplest of the looping structures in
C is the while statement. The while is an entry-controlled loop statement.
General form while (test condition) { body of the loop }
EXAMPLE OF WHILE STATEMENT
10.THE DO STATEMENT In certain situations, it is necessary to execute
the body of the loop at least once and then condition should be tested. In that situation do statement is used.
General form do { statement block; } while(condition);
EXAMPLE OF DO STATEMENT
11.THE FOR STATEMENT The for statement for loop is used to
repeatedly execute statement or block of statements fixed numbers of times.
General form for (initialization;test-
condition;increment) { body of the loop }
EXAMPLE OF FOR STATEMENT
Top Related