Your SlideShare is downloading. ×
0
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Control statement in c
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Control statement in c

2,117

Published on

Control statement in c

Control statement in c

Published in: Education, Technology, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,117
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
107
Comments
0
Likes
3
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

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

×