Skip to main content

C Decision Making Statements

 C CONTROL STATEMENTS

Control Statements in C language enable to determine flow of program using various kind of statement.In c language mostly program executed by sequence but control statements can change flow of program by making jump within program.

  3 Types of Control Statements are 




Decision Making Statements:- This Statements is also called conditional statements.In C language normally program executes in sequence but some times there are number of situation where programmer needed to change the sequence .This involved decision making to see whether particular condition is true or not.
          
Flow Chart Of Decision  Making Statements



Decision Making Statements support following statements:-

1.If Statement
2.If else Statement
3.If else if Statement
4.Nested if Statement
5.Switch Statements

1.If Statement:-  In C is used to if statements to control the program flow based on the condition. if statement is used to check the one or more condition.And In C if statements tests the condition. It executes the if block if condition is true.
Syntax 
if(condition)
{
//code to be executed
}
                                    if statements flow chart                                                
Flow chart of  if statements

 2.If-else statements:- The C if-else statement tests the condition.It execute the block if condition is true otherwise else block is executed.we can perform two operation in a single condition. that is one is for the true of that condition, and other for the false  of the condition.both block are cannot be executed in simantansouly. 
Syntax:-
if(condition)
{
//code to be executed if condition is true
}
else
{
//code to be executed if condition is false
}
                   if-else statement flow chart 




3.If else-if statement:-The if-else-if statement execute one condition from multiple statements. 
Syntax:-
if(condition 1)
{
//code to be executed if condition is true
}
else if(condition 2)
{
//code to be executed if condition is true
}
else if (condition 3)
{
//code to be executed if condition is true
}
else
{
//code to be executed if all the condition are false
}
                flow chart of if else-if statement 




4. Nested if statement:- The nested if statements represents the if block within another if block. the nested block condition executes only when outer if block condition is true. 
syntax:-
if(condition)
{
//code to be executed
if(condition)
{
// code to be executed
}
}
5.Switch Statement

The switch statements execute one statements from multiple condition.  

Rules of switch statement

πŸ‘‰πŸ» Switch expression and case value must be integer and character type.
πŸ‘‰πŸ»Case value must be consider within switch statement.
πŸ‘‰πŸ»The break statement in switch case is not must it is optional.

Syntax:-
switch(expression)
{
case value 1:
//code to be executed;
break;
case value 2:
//code to be executed;
break;
case value 3;
//code to be executed;
break;
.......
default:
//code to be executed if all cases are not matched;
}
                        Flow chart of switch statement

Switch Statement is Fall Through:- Without break statement all the statements are executed this condition is called fall through.
Syntax:-
switch(expression)
{
case value 1:
//code to be executed;
case value 2:
//code to be executed;
.......
default:
//code to be executed if all cases are not matched;
}

               NEXT STATEMENT AVAILABLE SOON AS......

Comments

Popular posts from this blog

Let's Be Technical

.   Programming Languages And There       Importance       Before you know about programming  language  we  must  know about languages. the language is a communication medium why which we can understand other person the language way of the transformation of various ideas and thoughts among people. After this  now we  know about programming language a programming language is a formal language, which comprises a set of instructions that produce various kinds of output. Programming languages are used in computer programming to implement algorithms. Most programming languages consist of instructions for computers. How its Importance of Programming Language Important in your daily life we use various device & tools that are works one the programming language like microwave ,ATM, Lift etc.  Programming language is important  because it define semantics and grammar which allow the programmers to effectively b  communicate with the machine that they program. A programming

Rapid View Of Technology

  Currently Running Top 10 Programming Languages C programming language                         C language is the most popular and and widely used programming language.The C language is developed in 1972 by  Dennis Ritchie at bell laboratories of AT&T American Telephone & Telegraph, located in the U.S.A . C language is also knows as mother and structured programming language.C language is a basic language of all other languages. C++ programming language                                 C++ is object oriented programming language. C++ programming language was developed in 1980 by Bjarne Stroustrup  at bell laboratories of AT&T,located in U.S.A  . C++ is totally based on oops concept. HTML                                                                                                                        Hyper Text Markup Language. html is a markup language it is not a programming language.   But it help full in programming language. html is a used to create web page

C Looping Statements

Looping/Iterative Statements What is Loop one statements are executed one or more time .looping simplify the complex problems into the easy one.loop provides code reusability.  we do not need to write same code again and again.looping is used to traverse the element of  data structure. Types of loops πŸ’₯ For Loop:- In C the For loop is used to iterate a part of the program many time.In the for loop number of iteration is fixed. Syntax:- for(initialization,condition,increment/decrement) { statement }                                   Flow chart of for loop Example                                                                      #include<stdio.h>    #include<conio.h>                                              void main()                            { int i=0; for(i=1;i<=10;i++) { printf("%d",i); } getch(); } Output 1 2 3 4 5 6 7 8 9 10 πŸ’₯ While loop:-While loop is also known as entry control loop Because  it first check t