SlideShare a Scribd company logo
1 of 20
FasilKM
fasilemv@gmail.com
www.facebook.com/Fasilfaas
twitter.com/fasilemv
in.linkedin.com/in/fasilemv
+919544334000
Control Structures in C
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
Control Structures
• System working
• Why control structures ?
• What is control Structures?
Styles of Control Structures in C
• Branching
• Looping
Branching
• What is Branching ?
• if statements
• ? : Operator
• switch statement
if statements
• If
• if (expression)
statement;
or
• if (expression)
{
Block of statements;
}
• If ……..else
if (expression)
{ Block of statements; }
else
{ Block of statements; }
• else if
if (expression)
{ Block of statements; }
else if(expression)
{ Block of statements; }
#include <stdio.h>
main() {
int cows = 6;
if (cows > 1)
printf("We have cowsn");
if (cows > 10)
printf("loads of them!n");
else
printf("Executing else part...!n");
if (cows == 5 )
{
printf("We have 5 cowsn");
}
else if( (cows == 6 )
{
printf("We have 6 cowsn");
}
We have cows
Executing else part...!
We have 6 cows
? : Operator
• Similar to if
• ternary operator
Eg
#include <stdio.h>
main()
{
int a , b;
a = 10;
printf( "Value of b is %dn", (a == 1) ? 20: 30 );
printf( "Value of b is %dn", (a == 10) ? 20: 30 );
}
Value of b is 30
Value of b is 20
switch statement
#include <stdio.h>
main()
{
int Grade = ‘ ’;
switch( Grade )
{
case 'A' : printf( "Excellentn" ); break;
case 'B' : printf( "Goodn" ); break;
case 'C' : printf( "OKn" ); break;
case 'D' : printf( "Mmmmm....n" ); break;
case 'F' : printf( "You must do better than thisn" ); break;
default : printf( "What is your grade anyway?n" ); break;
}
}
A
Excellent
B C D F def
Good
Ok
Mmmm
You must do ..
What is your
Looping
• What is looping
• for
• while
• dowhile
for loop
#include <stdio.h>
main()
{
int i;
for( i = 0; i <= j; i ++ )
{
printf("Hello %dn", i );
if( i == 6 )
{ break; }
}
}
Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
while
#include <stdio.h>
main()
{
int i = 0;
while ( i < 5 )
{
if(i==4)
continue;
printf("Hello %dn", i );
i = i -1;
}
}
Hello 0
Hello 1
Hello 2
Hello 5
do while
#include <stdio.h>
main()
{
int i = 10;
do{
printf("Hello %dn", i );
i = i -1;
if( i == 6 ) { break; }
}
while ( i > 0 );
}
Hello 10
Hello 9
Hello 8
Hello 7
Hello 6
#include <stdio.h>
main()
{
int i = 1;
do{
printf("Hello %dn", i );
i = i -1;
if( i == 6 ) { break; }
}
while ( i > 5 );
}
Hello 1
THANK YOU
Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Contact Us

More Related Content

Viewers also liked

Code igniter parameter passing techniques
Code igniter parameter passing techniquesCode igniter parameter passing techniques
Code igniter parameter passing techniquesRakhitha Ratnayake
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHPBradley Holt
 

Viewers also liked (16)

Php.ini
Php.iniPhp.ini
Php.ini
 
Magic methods in php
Magic methods in phpMagic methods in php
Magic methods in php
 
Client Side scripting and server side scripting
Client Side scripting and server side scriptingClient Side scripting and server side scripting
Client Side scripting and server side scripting
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
Php.ini
Php.iniPhp.ini
Php.ini
 
Session,cookies and get and post methods
Session,cookies  and get and post methodsSession,cookies  and get and post methods
Session,cookies and get and post methods
 
Code igniter parameter passing techniques
Code igniter parameter passing techniquesCode igniter parameter passing techniques
Code igniter parameter passing techniques
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php functions
Php functionsPhp functions
Php functions
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 

Similar to Control structure

A3 sec -_regular_expressions
A3 sec -_regular_expressionsA3 sec -_regular_expressions
A3 sec -_regular_expressionsa3sec
 
Session05 iteration structure
Session05 iteration structureSession05 iteration structure
Session05 iteration structureHarithaRanasinghe
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop kapil078
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c programNishmaNJ
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshareGagan Deep
 
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...WebStackAcademy
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.comGreen Ecosystem
 
DIG1108C Lesson3 Fall 2014
DIG1108C Lesson3 Fall 2014DIG1108C Lesson3 Fall 2014
DIG1108C Lesson3 Fall 2014David Wolfpaw
 
Some stuff about C++ and development
Some stuff about C++ and developmentSome stuff about C++ and development
Some stuff about C++ and developmentJon Jagger
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops Hemantha Kulathilake
 
Programming basics
Programming basicsProgramming basics
Programming basics246paa
 

Similar to Control structure (20)

A3 sec -_regular_expressions
A3 sec -_regular_expressionsA3 sec -_regular_expressions
A3 sec -_regular_expressions
 
Introduction to c part -1
Introduction to c   part -1Introduction to c   part -1
Introduction to c part -1
 
Session05 iteration structure
Session05 iteration structureSession05 iteration structure
Session05 iteration structure
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
 
Looping
LoopingLooping
Looping
 
Control structure in c
Control structure in cControl structure in c
Control structure in c
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in CSPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
 
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
 
DIG1108C Lesson3 Fall 2014
DIG1108C Lesson3 Fall 2014DIG1108C Lesson3 Fall 2014
DIG1108C Lesson3 Fall 2014
 
Some stuff about C++ and development
Some stuff about C++ and developmentSome stuff about C++ and development
Some stuff about C++ and development
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 
Bsit1
Bsit1Bsit1
Bsit1
 
UNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptxUNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptx
 
C Language Lecture 7
C Language Lecture 7C Language Lecture 7
C Language Lecture 7
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
C tutorial
C tutorialC tutorial
C tutorial
 

More from baabtra.com - No. 1 supplier of quality freshers

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 
Baabtra soft skills
Baabtra soft skillsBaabtra soft skills
Baabtra soft skills
 
Cell phone jammer
Cell phone jammerCell phone jammer
Cell phone jammer
 
Apple iwatches
Apple iwatchesApple iwatches
Apple iwatches
 
Driverless car
Driverless carDriverless car
Driverless car
 
Brain computer interface(neethu,bincy,sanooja)
Brain computer interface(neethu,bincy,sanooja)Brain computer interface(neethu,bincy,sanooja)
Brain computer interface(neethu,bincy,sanooja)
 
Chapter 5 : How To Program
Chapter  5 : How To ProgramChapter  5 : How To Program
Chapter 5 : How To Program
 
Chapter 5 : How To Program?
Chapter  5 : How To Program?Chapter  5 : How To Program?
Chapter 5 : How To Program?
 

Control structure

  • 1.
  • 3. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 4. Control Structures • System working • Why control structures ? • What is control Structures?
  • 5. Styles of Control Structures in C • Branching • Looping
  • 6. Branching • What is Branching ? • if statements • ? : Operator • switch statement
  • 7. if statements • If • if (expression) statement; or • if (expression) { Block of statements; }
  • 8. • If ……..else if (expression) { Block of statements; } else { Block of statements; } • else if if (expression) { Block of statements; } else if(expression) { Block of statements; }
  • 9. #include <stdio.h> main() { int cows = 6; if (cows > 1) printf("We have cowsn"); if (cows > 10) printf("loads of them!n"); else printf("Executing else part...!n"); if (cows == 5 ) { printf("We have 5 cowsn"); } else if( (cows == 6 ) { printf("We have 6 cowsn"); } We have cows Executing else part...! We have 6 cows
  • 10. ? : Operator • Similar to if • ternary operator Eg #include <stdio.h> main() { int a , b; a = 10; printf( "Value of b is %dn", (a == 1) ? 20: 30 ); printf( "Value of b is %dn", (a == 10) ? 20: 30 ); } Value of b is 30 Value of b is 20
  • 11. switch statement #include <stdio.h> main() { int Grade = ‘ ’; switch( Grade ) { case 'A' : printf( "Excellentn" ); break; case 'B' : printf( "Goodn" ); break; case 'C' : printf( "OKn" ); break; case 'D' : printf( "Mmmmm....n" ); break; case 'F' : printf( "You must do better than thisn" ); break; default : printf( "What is your grade anyway?n" ); break; } } A Excellent B C D F def Good Ok Mmmm You must do .. What is your
  • 12. Looping • What is looping • for • while • dowhile
  • 13. for loop #include <stdio.h> main() { int i; for( i = 0; i <= j; i ++ ) { printf("Hello %dn", i ); if( i == 6 ) { break; } } } Hello 0 Hello 1 Hello 2 Hello 3 Hello 4 Hello 5 Hello 6
  • 14. while #include <stdio.h> main() { int i = 0; while ( i < 5 ) { if(i==4) continue; printf("Hello %dn", i ); i = i -1; } } Hello 0 Hello 1 Hello 2 Hello 5
  • 15. do while #include <stdio.h> main() { int i = 10; do{ printf("Hello %dn", i ); i = i -1; if( i == 6 ) { break; } } while ( i > 0 ); } Hello 10 Hello 9 Hello 8 Hello 7 Hello 6
  • 16. #include <stdio.h> main() { int i = 1; do{ printf("Hello %dn", i ); i = i -1; if( i == 6 ) { break; } } while ( i > 5 ); } Hello 1
  • 18. Want to learn more about programming or Looking to become a good programmer? Are you wasting time on searching so many contents online? Do you want to learn things quickly? Tired of spending huge amount of money to become a Software professional? Do an online course @ baabtra.com We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.
  • 19. Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Give a feedback @ massbaab.com/baabtra Thanks in advance www.baabtra.com | www.massbaab.com |www.baabte.com
  • 20. Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com Contact Us