SlideShare a Scribd company logo
CONTROL STATEMENTS
In C Programming
1. If statement
• This is the most simple form of the branching
statements.
• It takes an expression in parenthesis and an
statement or block of statements expresses, if
the expression is true then the statement or
block of statements gets executed otherwise
these statements are skipped.
NOTE: Expression will be assumed to be true
if its evaluated values is non-zero.
11/14/2017 VIGNAN'S UNIVERSITY 2
SYNTAX
Syntax:
if (expression)
statement;
or
if (expression)
{
Block of statements;
}
11/14/2017 VIGNAN'S UNIVERSITY 3
2.If Else Statement:
• An if statement can be followed by an optional else
statement, which executes when the Boolean expression is
false.
• Syntax
if(boolean_expression)
{
statement(s);
}
Else
{
statement(s)
}
11/14/2017 VIGNAN'S UNIVERSITY 4
Flowchart of if...else statement
11/14/2017 VIGNAN'S UNIVERSITY 5
3. Nested IF....ELSE
• The if...else statement executes two different codes
depending upon whether the test expression is true
or false. Sometimes, a choice has to be made from
more than 2 possibilities.
In Nested if .....else, the if and else part can contain
one or more if else statements.
11/14/2017 VIGNAN'S UNIVERSITY 6
Syntax
if(conditional-expression)
{
if(conditional-expression)
{
statements;
}
else
{
statements;
}
statements;
}
else
{
if(conditional-expression)
{
statements;
}
statements;
}11/14/2017 VIGNAN'S UNIVERSITY 7
4. ELSE .... IF LADDER
• If we are having different – different test
conditions with different – different
statements, then for these kind of
programming we need else if leader. Else if the
leader is not interdependent to any other
statements or any other test conditions.
11/14/2017 VIGNAN'S UNIVERSITY 8
Syntax:if(test condition)
{
}
else if(condition)
{
}
else if(condition)
{
}
else
{
}
This construct is known as the else if ladder
11/14/2017 VIGNAN'S UNIVERSITY 9
ii. Switch Statement
• The switch statement is often faster than nested
if...else (not always). Also, the syntax of switch
statement is cleaner and easy to understand.
• When a case constant is found that matches the
switch expression, control of the program passes
to the block of code associated with that case.
• The break statement is used to prevent the code
running into the next case.
11/14/2017 VIGNAN'S UNIVERSITY 10
Flow Diagram
11/14/2017 VIGNAN'S UNIVERSITY 11
II. Looping
• Loops provide a way to repeat commands and
control how many times they are repeated. C
provides a number of looping way.
1. While loop
2. do...while loop
3. for loop
11/14/2017 VIGNAN'S UNIVERSITY 12
While loop
• The most basic loop in C is the while loop.A
while statement is like a repeating if
statement. Like an If statement, if the test
condition is true: the statments get executed.
The difference is that after the statements
have been executed, the test condition is
checked again. If it is still true the statements
get executed again. This cycle repeats until the
test condition evaluates to false.
11/14/2017 VIGNAN'S UNIVERSITY 13
Syntax
while ( expression )
{
Single statement
or
Block of statements;
}
11/14/2017 VIGNAN'S UNIVERSITY 14
Flowchart of while loop
11/14/2017 VIGNAN'S UNIVERSITY 15
do...while loop
• do ... while is just like a while loop except that
the test condition is checked at the end of the
loop rather than the start. This has the effect
that the content of the loop are always
executed at least once.
11/14/2017 VIGNAN'S UNIVERSITY 16
Syntax
Do
{
Single statement
or
Block of statements;
}while(expression);
11/14/2017 VIGNAN'S UNIVERSITY 17
Flow Chart
11/14/2017 VIGNAN'S UNIVERSITY 18
for loop
• for loop is similar to while, it's just written
differently.for statements are often used to
proccess lists such a range of numbers:
• In the syntax:
expression1 - Initialisese variables.
expression2 - Condtional expression, as long as this
condition is true, loop will keep executing.
expression3 - expression3 is the modifier which may
be simple increment of a variable.
11/14/2017 VIGNAN'S UNIVERSITY 19
Syntax
for( expression1; expression2; expression3)
{
Single statement
or
Block of statements;
}
11/14/2017 VIGNAN'S UNIVERSITY 20
Exercises
Refer word doc
11/14/2017 VIGNAN'S UNIVERSITY 21
Thank you
11/14/2017 VIGNAN'S UNIVERSITY 22

More Related Content

What's hot

Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
Niloy Saha
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
baabtra.com - No. 1 supplier of quality freshers
 
Vb decision making statements
Vb decision making statementsVb decision making statements
Vb decision making statements
pragya ratan
 
Decision statements in vb.net
Decision statements in vb.netDecision statements in vb.net
Decision statements in vb.netilakkiya
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
Hossain Md Shakhawat
 
Conditional statements
Conditional statementsConditional statements
Conditional statementscherrybear2014
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
It Academy
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
eShikshak
 
Cse lecture-7-c loop
Cse lecture-7-c loopCse lecture-7-c loop
Cse lecture-7-c loop
FarshidKhan
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
Raj Parekh
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in JavaRavi_Kant_Sahu
 
Selection statements
Selection statementsSelection statements
Selection statements
Harsh Dabas
 
Control satkcher ppt
Control satkcher pptControl satkcher ppt
Control satkcher ppt
6336Zeelvora
 
Java loops for, while and do...while
Java loops   for, while and do...whileJava loops   for, while and do...while
Java loops for, while and do...while
Jayfee Ramos
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
Jyoti Bhardwaj
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statements
jyoti_lakhani
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
Hossain Md Shakhawat
 
Chapter 4 java
Chapter 4 javaChapter 4 java
Chapter 4 java
Ahmad sohail Kakar
 
If-else and switch-case
If-else and switch-caseIf-else and switch-case
If-else and switch-case
Manash Kumar Mondal
 

What's hot (20)

Control Statements in Java
Control Statements in JavaControl Statements in Java
Control Statements in Java
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 
Vb decision making statements
Vb decision making statementsVb decision making statements
Vb decision making statements
 
Data structures vb
Data structures vbData structures vb
Data structures vb
 
Decision statements in vb.net
Decision statements in vb.netDecision statements in vb.net
Decision statements in vb.net
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
 
Conditional statements
Conditional statementsConditional statements
Conditional statements
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Cse lecture-7-c loop
Cse lecture-7-c loopCse lecture-7-c loop
Cse lecture-7-c loop
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
 
Control structures in Java
Control structures in JavaControl structures in Java
Control structures in Java
 
Selection statements
Selection statementsSelection statements
Selection statements
 
Control satkcher ppt
Control satkcher pptControl satkcher ppt
Control satkcher ppt
 
Java loops for, while and do...while
Java loops   for, while and do...whileJava loops   for, while and do...while
Java loops for, while and do...while
 
Constructs (Programming Methodology)
Constructs (Programming Methodology)Constructs (Programming Methodology)
Constructs (Programming Methodology)
 
java programming- control statements
 java programming- control statements java programming- control statements
java programming- control statements
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Chapter 4 java
Chapter 4 javaChapter 4 java
Chapter 4 java
 
If-else and switch-case
If-else and switch-caseIf-else and switch-case
If-else and switch-case
 

Similar to Control statements

Decision making and looping - c programming by YEASIN NEWAJ
Decision making and looping -  c programming by YEASIN NEWAJDecision making and looping -  c programming by YEASIN NEWAJ
Decision making and looping - c programming by YEASIN NEWAJ
YeasinNewaj
 
UNIT 2 PPT.pdf
UNIT 2 PPT.pdfUNIT 2 PPT.pdf
UNIT 2 PPT.pdf
DhanushKumar610673
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
TANUJ ⠀
 
Control_Statements.pptx
Control_Statements.pptxControl_Statements.pptx
Control_Statements.pptx
Koteswari Kasireddy
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
Madishetty Prathibha
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
web presentation 138.pptx
web presentation 138.pptxweb presentation 138.pptx
web presentation 138.pptx
AbhiYadav655132
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
Eng Teong Cheah
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6
Mohd Harris Ahmad Jaal
 
Control statements
Control statementsControl statements
Control statements
CutyChhaya
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
jaychoudhary37
 
Ch # 11 2nd year computer science notes1
Ch # 11 2nd year computer science notes1Ch # 11 2nd year computer science notes1
Ch # 11 2nd year computer science notes1
muhammadFaheem656405
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
Deepak Lakhlan
 
DECISION MAKING.pptx
DECISION MAKING.pptxDECISION MAKING.pptx
DECISION MAKING.pptx
Ayshwarya Baburam
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
RAJ KUMAR
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual BasicTushar Jain
 
Flow control in c++
Flow control in c++Flow control in c++
Flow control in c++
Subhasis Nayak
 
nuts and bolts of c++
nuts and bolts of c++nuts and bolts of c++
nuts and bolts of c++
guestfb6ada
 

Similar to Control statements (20)

Decision making and looping - c programming by YEASIN NEWAJ
Decision making and looping -  c programming by YEASIN NEWAJDecision making and looping -  c programming by YEASIN NEWAJ
Decision making and looping - c programming by YEASIN NEWAJ
 
UNIT 2 PPT.pdf
UNIT 2 PPT.pdfUNIT 2 PPT.pdf
UNIT 2 PPT.pdf
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Control_Statements.pptx
Control_Statements.pptxControl_Statements.pptx
Control_Statements.pptx
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
web presentation 138.pptx
web presentation 138.pptxweb presentation 138.pptx
web presentation 138.pptx
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)
 
Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6Fundamentals of Programming Chapter 6
Fundamentals of Programming Chapter 6
 
Control statements
Control statementsControl statements
Control statements
 
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
FAL(2022-23)_FRESHERS_CSE1012_ETH_AP2022234000166_Reference_Material_I_15-Nov...
 
Ch # 11 2nd year computer science notes1
Ch # 11 2nd year computer science notes1Ch # 11 2nd year computer science notes1
Ch # 11 2nd year computer science notes1
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
 
DECISION MAKING.pptx
DECISION MAKING.pptxDECISION MAKING.pptx
DECISION MAKING.pptx
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
Control Structures in Visual Basic
Control Structures in  Visual BasicControl Structures in  Visual Basic
Control Structures in Visual Basic
 
Flow control in c++
Flow control in c++Flow control in c++
Flow control in c++
 
nuts and bolts of c++
nuts and bolts of c++nuts and bolts of c++
nuts and bolts of c++
 

More from NAGUR SHAREEF SHAIK

Perceptron & Neural Networks
Perceptron & Neural NetworksPerceptron & Neural Networks
Perceptron & Neural Networks
NAGUR SHAREEF SHAIK
 
Theories on moral autonomy
Theories on moral autonomyTheories on moral autonomy
Theories on moral autonomy
NAGUR SHAREEF SHAIK
 
Internet of things(IoT)
Internet of things(IoT)Internet of things(IoT)
Internet of things(IoT)
NAGUR SHAREEF SHAIK
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
NAGUR SHAREEF SHAIK
 
Quantum Computers
Quantum ComputersQuantum Computers
Quantum Computers
NAGUR SHAREEF SHAIK
 
Biodiversity and its conservation
Biodiversity and its  conservationBiodiversity and its  conservation
Biodiversity and its conservation
NAGUR SHAREEF SHAIK
 
PHOTONIC CRYSTALS
PHOTONIC CRYSTALSPHOTONIC CRYSTALS
PHOTONIC CRYSTALS
NAGUR SHAREEF SHAIK
 
Gravitational waves
Gravitational wavesGravitational waves
Gravitational waves
NAGUR SHAREEF SHAIK
 
WASTE WATER TREATMENT
WASTE WATER TREATMENTWASTE WATER TREATMENT
WASTE WATER TREATMENT
NAGUR SHAREEF SHAIK
 
Quantum computers
Quantum computersQuantum computers
Quantum computers
NAGUR SHAREEF SHAIK
 

More from NAGUR SHAREEF SHAIK (10)

Perceptron & Neural Networks
Perceptron & Neural NetworksPerceptron & Neural Networks
Perceptron & Neural Networks
 
Theories on moral autonomy
Theories on moral autonomyTheories on moral autonomy
Theories on moral autonomy
 
Internet of things(IoT)
Internet of things(IoT)Internet of things(IoT)
Internet of things(IoT)
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
 
Quantum Computers
Quantum ComputersQuantum Computers
Quantum Computers
 
Biodiversity and its conservation
Biodiversity and its  conservationBiodiversity and its  conservation
Biodiversity and its conservation
 
PHOTONIC CRYSTALS
PHOTONIC CRYSTALSPHOTONIC CRYSTALS
PHOTONIC CRYSTALS
 
Gravitational waves
Gravitational wavesGravitational waves
Gravitational waves
 
WASTE WATER TREATMENT
WASTE WATER TREATMENTWASTE WATER TREATMENT
WASTE WATER TREATMENT
 
Quantum computers
Quantum computersQuantum computers
Quantum computers
 

Recently uploaded

Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 

Recently uploaded (20)

Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 

Control statements

  • 2. 1. If statement • This is the most simple form of the branching statements. • It takes an expression in parenthesis and an statement or block of statements expresses, if the expression is true then the statement or block of statements gets executed otherwise these statements are skipped. NOTE: Expression will be assumed to be true if its evaluated values is non-zero. 11/14/2017 VIGNAN'S UNIVERSITY 2
  • 3. SYNTAX Syntax: if (expression) statement; or if (expression) { Block of statements; } 11/14/2017 VIGNAN'S UNIVERSITY 3
  • 4. 2.If Else Statement: • An if statement can be followed by an optional else statement, which executes when the Boolean expression is false. • Syntax if(boolean_expression) { statement(s); } Else { statement(s) } 11/14/2017 VIGNAN'S UNIVERSITY 4
  • 5. Flowchart of if...else statement 11/14/2017 VIGNAN'S UNIVERSITY 5
  • 6. 3. Nested IF....ELSE • The if...else statement executes two different codes depending upon whether the test expression is true or false. Sometimes, a choice has to be made from more than 2 possibilities. In Nested if .....else, the if and else part can contain one or more if else statements. 11/14/2017 VIGNAN'S UNIVERSITY 6
  • 8. 4. ELSE .... IF LADDER • If we are having different – different test conditions with different – different statements, then for these kind of programming we need else if leader. Else if the leader is not interdependent to any other statements or any other test conditions. 11/14/2017 VIGNAN'S UNIVERSITY 8
  • 9. Syntax:if(test condition) { } else if(condition) { } else if(condition) { } else { } This construct is known as the else if ladder 11/14/2017 VIGNAN'S UNIVERSITY 9
  • 10. ii. Switch Statement • The switch statement is often faster than nested if...else (not always). Also, the syntax of switch statement is cleaner and easy to understand. • When a case constant is found that matches the switch expression, control of the program passes to the block of code associated with that case. • The break statement is used to prevent the code running into the next case. 11/14/2017 VIGNAN'S UNIVERSITY 10
  • 12. II. Looping • Loops provide a way to repeat commands and control how many times they are repeated. C provides a number of looping way. 1. While loop 2. do...while loop 3. for loop 11/14/2017 VIGNAN'S UNIVERSITY 12
  • 13. While loop • The most basic loop in C is the while loop.A while statement is like a repeating if statement. Like an If statement, if the test condition is true: the statments get executed. The difference is that after the statements have been executed, the test condition is checked again. If it is still true the statements get executed again. This cycle repeats until the test condition evaluates to false. 11/14/2017 VIGNAN'S UNIVERSITY 13
  • 14. Syntax while ( expression ) { Single statement or Block of statements; } 11/14/2017 VIGNAN'S UNIVERSITY 14
  • 15. Flowchart of while loop 11/14/2017 VIGNAN'S UNIVERSITY 15
  • 16. do...while loop • do ... while is just like a while loop except that the test condition is checked at the end of the loop rather than the start. This has the effect that the content of the loop are always executed at least once. 11/14/2017 VIGNAN'S UNIVERSITY 16
  • 17. Syntax Do { Single statement or Block of statements; }while(expression); 11/14/2017 VIGNAN'S UNIVERSITY 17
  • 19. for loop • for loop is similar to while, it's just written differently.for statements are often used to proccess lists such a range of numbers: • In the syntax: expression1 - Initialisese variables. expression2 - Condtional expression, as long as this condition is true, loop will keep executing. expression3 - expression3 is the modifier which may be simple increment of a variable. 11/14/2017 VIGNAN'S UNIVERSITY 19
  • 20. Syntax for( expression1; expression2; expression3) { Single statement or Block of statements; } 11/14/2017 VIGNAN'S UNIVERSITY 20
  • 21. Exercises Refer word doc 11/14/2017 VIGNAN'S UNIVERSITY 21