Control statement in c
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share
  • 1,462 views

Control statement in c

Control statement in c

Statistics

Views

Total Views
1,462
Views on SlideShare
1,462
Embed Views
0

Actions

Likes
0
Downloads
45
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Control statement in c Presentation Transcript

  • 1. 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
  • 2. Control statement in cShanu k k shanukk89@gmail.com www.facebook.com/shanunn i twitter.com/shanu in.linkedin.com/in/shanu 9656153432
  • 3. • C provides two sytles of flow control: • Branching • Looping
  • 4. If statement • It takes an expression in parenthesis and an statement or block of statements. if the expression is true then the statement or block of statements gets executed otherwise these statements are skipped.
  • 5. If(test expression) Statement; Or If (test expression) { Block of statements1; } Else { Statement2; }
  • 6. Switch statement • A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.
  • 7. Switch( expression) { case 1 Statement 1 Break; } Case2 Statement 2 Break; }
  • 8. • Depending on the position of control statement in c,control structure may be classified • Entry_ controlled loop • Exit _controlled loop
  • 9. False true Entry controlled loop exit controlled loop Test conditio n ? Body of the loop Body of the loop Test conditio n ?
  • 10. • C language provides three constructs for perfoming loop operations • While statement • Do statements • For statements
  • 11. While(test condition) { body of the loop }
  • 12. ……………………… ……………………… int_sum=0; int_n=1; while(int_n<=10) { int_sum=int_sum+int_n; int_n=int_n+1; } printf(“sum=%dn”,int_sum); …………………………………………..
  • 13. Do statement do { Body of the loop } While(test condition)
  • 14. int_i=1; int_sum=0; do { int_sum=int_sum+I i=i+2; } while(sum<40||i<10); printf(“%d %dn,I,sum);
  • 15. For statements For(intialization;testcondition;icrement) { body of the loop }
  • 16. • Intialization of control variable done first using assignment statement • The value of control variable tested using test condition,ie reletional expression such as i>10,that determine when the loop will exit • If the condition is true ,the body of loop executed,otherwise terminated
  • 17. int_sum=0; for(int_n=1;int_n<=10;int_n++) { int_sum=int_sum+int_n; } printf(“sum=%dn”,int_sum);
  • 18. additional features of for loop 1. More than one variable can be intialized atb a time 2. More than one variable incremented at a time 3. The thest condition may have compound relation 4. One or more sections can be omitted ,if necessary eg: m=5; for(;m!=100;) { printf(“%dn”,m) m=m+5; }
  • 19. Nesting of for loop For(i=0;i<n;i++) { ……………………………… For(j=0;j<n-1;j++) { ……………………………… } }
  • 20. Jumping out of a loop • Exit from a loop using break statement if a break statement encounteredd in a loop,the loop will immidiatly exited and the program continues with the statement immidiatly following loop;ie break will exit only a single loop
  • 21. Eg: while(test condition) { …………………………….. ……………………………… if(condition) break;
  • 22. Skipping a part of loop Another statement ‘continue’, • It tells the compiler skip the following statements and continue with next iteration Eg: While (test condition) { ……………………….. If(…………) Continue;
  • 23. ???
  • 24. Contact Us 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 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com