SlideShare uma empresa Scribd logo
1 de 39
PREPARED BY- PRADEEP DWIVEDI(persuingB.TECH-IT) 	from HINDUSTAN COLLEGE OF SCIENCE AND 			  TECHNOLOGY(MATHURA) 	MOB-+919027843806 	E-MAIL-pradeep.it74@gmail.com	 C-PROGRAMMING SLIDE-4 Wednesday, September 01, 2010 1 PRADEEP DWIVEDI
C-4 TOPIC:- Loop break statement continue statement go to statement Wednesday, September 01, 2010 2 PRADEEP DWIVEDI
LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 3 when we want to repeat a particular task again and again that time we use the loop. loop is a control structure that repeats a group of sets in a program. there are three loops in c- while  for do while
WHILE LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 4 syntax:- while(test-condition) { body of the loop. }
WHILE LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 5 the while loop is a entry controlled loop statement. the test condition is evaluated and if the condition is true then the body of loop is executed. after execution of the body the test condition is once again evaluated and if it is true the body is executed once again. this process of repeated execution of the body continues until the test condition finally becomes false and controlled is transferred out of the loop.
FLOW CHART(WHILE LOOP) Wednesday, September 01, 2010 PRADEEP DWIVEDI 6
PROG13 Wednesday, September 01, 2010 PRADEEP DWIVEDI 7 /* w a p to print 1 to 10  */ #include<stdio.h> #include<conio.h> void main() { inti; clrscr(); i=1; while(i<=10) { printf("%d",i); i++; } getch(); }
DO WHILE LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 8 in while loop, makes a test of condition before the loop is executed. therefore, the body of the loop may not be executed at all if the condition is not satisfied at the very first attempt. on a some situations it must be necessary to execute the body of the loop before the test is performed.  such situation can be handled with the help of the do statement.
DO WHILE LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 9 syntax:- do { body of the loop           (true) } while(test-condition);
DO WHILE LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 10 in the do while loop it first execute the body and then checks the condition. so if the condition is initially false, it execute atleast once.
prog14 Wednesday, September 01, 2010 PRADEEP DWIVEDI 11 /* w.a.p. to print 1 TO 10 digit */ #include<stdio.h> #include<conio.h> void main() { inti; clrscr(); i=1; do { printf("%d",i); i++; } while(i<=10); getch(); }
FOR LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 12 It is two type if simple for loop. nested for loop.
FOR LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 13 syntax:- for(initialization; test of the condition; increment/decrement) { body of loop }
FOR LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 14 in a for loop we always follows the following 4 steps sequentially. initialize the value. test the condition (if it is true) execute the body. increment/decrement the value.
FOR LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 15 eg:- for(i=1;i<=10;i++) { printf(“%d”,i); } 1 2 4 false true 3
prog15 /* w.a.p. to check the entered number is a prime number or not */ #include<stdio.h> #include<conio.h> #include<process.h> void main() { inti,num; clrscr(); printf("Enter a number"); scanf("%d",&num); for(i=2;i<num;i++) { if(num%i==0) { printf("number is not prime"); getch(); exit(0); } } printf("Number is prime"); getch(); } Wednesday, September 01, 2010 16 PRADEEP DWIVEDI
SOME POINTS Wednesday, September 01, 2010 PRADEEP DWIVEDI 17 exit() is a predefine function with the help of it we move out or terminate from the program. it comes from process.h header file. when we use semicolon after the for loop that time it become a self executed loop and it execute when condition become false. we can have more than one initialization and the iteration in a for loop. eg. for(i=1;j=10;i<=10;i++; j--)
prog16 Wednesday, September 01, 2010 PRADEEP DWIVEDI 18 /*w.a.p. to calculate factorial of a given number */ #include<stdio.h> #include<conio.h> void main() { intn,i,fac=1; clrscr(); printf("Enter a number whose factorial is found :"); scanf("%d",&n); for(i=n;i>=1;i--) { fac=fac*i; } printf("factorial is:%d",fac); getch(); }
prog17 Wednesday, September 01, 2010 PRADEEP DWIVEDI 19 /* w.a.p. to print fabonicai series  1 1 2 3 5 8 13 21 34 55 89 144 223 337 */ #include<stdio.h> #include<conio.h> void main() { int num1,num2; clrscr(); num1=num2=1; printf("%d",num2); while(num2<=200) { printf("%d",num2); num2=num2+num1; num1=num2-num1; } getch(); }
NESTED FOR LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 20 nesting of loops, that is, one for statement with in another for statement is allowed in c. eg. 		for(i=1;i<10;++i)   { 		for(j=1;j<5;++j)       {        }         } outer loop inner loop
prog18 /* print this pattern 	1 	1 2  	1 2 3 	1 2 3 4 	1 2 3 4 5                        */ #include<stdio.h> #include<conio.h> void main() { inti,j,num; clrscr(); printf("Enter the number :"); scanf("%d",&num); for(i=1;i<=num;i++) { for(j=1;j<=i;j++) { printf("%d",j); } printf(""); } getch(); } Wednesday, September 01, 2010 21 PRADEEP DWIVEDI
prog19 /* w.a.p. to print this pattern 	* * * * * 	* * * * 	* * *  	* * 	* */ #include<stdio.h> #include<conio.h> void main() { inti,j; clrscr(); for(i=1;i<=5;i++) { for(j=5;j>=i;j--) { printf("* "); } printf(""); } getch(); } Wednesday, September 01, 2010 22 PRADEEP DWIVEDI
JUMPING IN THE LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 23 For jumping in the loop we use two statements: break continue
THE BREAK STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 24 break is a keyword with the help of it we jump out from the loop. break is only use in the loop and switch case.
SYNTAX FOR BREAK STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 25 A.             while(………..)         { 		……. 		……..       if (condition) 		break; 		……. 		} exit from loop
SYNTAX FOR BREAK STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 26 B.    do 	{     …….. 		if(condition) 		break; 		………. 		………. 		} 		while(………); exit from loop
SYNTAX FOR BREAK STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 27 C. 	for(……………………………………) 	{ 	---------    ---------       if(condition) 		break; 		------- 		-------        } 	------ exit from loop
SYNTAX FOR BREAK STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 28 D. 	for(……………………………….) 	{ 		……… 		for(……………………..) 		{ 			if(condition) 			break; 			… 			} 			.. 			} exit from inner loop
prog20 /*w.a.p. to determine wheather a number is prime or not(using break statement)*/ #include<stdio.h> #include<conio.h> void main() { intnum,i; clrscr(); printf("Enter a number: "); scanf("%d",&num); i=2; while(i<num) { if(num%i==0) { printf("number is not prime");  break; 	} i++; } if(i==num) printf("number is prime"); getch(); } Wednesday, September 01, 2010 29 PRADEEP DWIVEDI
goto STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 30 goto keyword (statement) can transfers the control to any place in a program, it is useful to provide branching with in a loop.
SYNTAX OF GOTO STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 31 while(………..)                                              (A) { if(error) goto stop; ……. ……  if(condition) gotoabc; ………. ………. abc: …….. } stop: ………… jump with in loop exit from loop
SYNTAX OF GOTO STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 32 for(………………..)                      (B) { …….. …….. 	for(…….) 	{ 	…… 	….... if(error) goto error; …….. } ….. } error: ….. …….
SOME POINTS Wednesday, September 01, 2010 PRADEEP DWIVEDI 33 in syntax(A) if the condition is satisfied goto statement transfers control to the label abc:   stop: abc:   error: called  label
prog21 /* Demo for goto statement */ #include<stdio.h> #include<conio.h> void main() { inti,j,k; clrscr(); for(i=1;i<=3;i++) { for(j=1;j<=3;j++) { for(k=1;k<=3;k++) { if(i==3&&j==3&&k==3) goto out; else printf("%d%d%d",i,j,k); } } } out: printf("out of the loop at last!"); getch(); } Wednesday, September 01, 2010 34 PRADEEP DWIVEDI
SKIPPING A PART OF A LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 35 For skipping a part of a loop we use continue keyword. the continue statement tells the compiler ,”skip the following statements and continue with next iteration”. the format of continue statement is simply: continue; continue:- is a keyword with the help of that we can move up at the beginning of the loop.
SYNTAX Wednesday, September 01, 2010 PRADEEP DWIVEDI 36 A. 	while(test-condition) 	{ 	continue; 	…….. 	…….. 	}
SYNTAX Wednesday, September 01, 2010 PRADEEP DWIVEDI 37 B. 		do 		{ 	………. 	………. 		if(……..) 		continue; 		…….. 		…….. 			} 	while(test-condition);
SYNTAX Wednesday, September 01, 2010 PRADEEP DWIVEDI 38 C.  for(initialization;test-condition;increment) 		{ 	………….. 	………….. 		if(………….) 		continue; 		………. 		………. 		}
prog22 Wednesday, September 01, 2010 PRADEEP DWIVEDI 39 /* Demo for break statement  */ #include<stdio.h> #include<conio.h> void main() { inti; for(i=0;i<=10;i++) { if(i==5) continue; printf("Er.pradeepdwivedi"); } getch(); }

Mais conteúdo relacionado

Mais procurados

6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumpingMomenMostafa
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statementsMomenMostafa
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumlercorehard_by
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c programNishmaNJ
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointersMomenMostafa
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string libraryMomenMostafa
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin cVikash Dhal
 
Programming in c function
Programming in c functionProgramming in c function
Programming in c functionParvez Ahmed
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manualSANTOSH RATH
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rathSANTOSH RATH
 

Mais procurados (20)

Lập trình C
Lập trình CLập trình C
Lập trình C
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
Loops in R
Loops in RLoops in R
Loops in R
 
Data struture lab
Data struture labData struture lab
Data struture lab
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
 
Array strings
Array stringsArray strings
Array strings
 
Lecture 8- Data Input and Output
Lecture 8- Data Input and OutputLecture 8- Data Input and Output
Lecture 8- Data Input and Output
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
 
175035 cse lab-05
175035 cse lab-05 175035 cse lab-05
175035 cse lab-05
 
Programming in c function
Programming in c functionProgramming in c function
Programming in c function
 
Lecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C ProgrammingLecture 6- Intorduction to C Programming
Lecture 6- Intorduction to C Programming
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Data structure new lab manual
Data structure  new lab manualData structure  new lab manual
Data structure new lab manual
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
 

Semelhante a C programming slide c04

Semelhante a C programming slide c04 (20)

C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Loops in c
Loops in cLoops in c
Loops in c
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 
Decision Making and Looping
Decision Making and LoopingDecision Making and Looping
Decision Making and Looping
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
175035-cse LAB-04
175035-cse LAB-04 175035-cse LAB-04
175035-cse LAB-04
 
Loops
LoopsLoops
Loops
 
C programming Control Structure.pptx
C programming Control Structure.pptxC programming Control Structure.pptx
C programming Control Structure.pptx
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
 
Loops
LoopsLoops
Loops
 
Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020
 
Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020Week2 ch4 part1edited 2020
Week2 ch4 part1edited 2020
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
For Loop
For LoopFor Loop
For Loop
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
C.pdf
C.pdfC.pdf
C.pdf
 
C Language Lecture 7
C Language Lecture 7C Language Lecture 7
C Language Lecture 7
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 

Último

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 

Último (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 

C programming slide c04

  • 1. PREPARED BY- PRADEEP DWIVEDI(persuingB.TECH-IT) from HINDUSTAN COLLEGE OF SCIENCE AND TECHNOLOGY(MATHURA) MOB-+919027843806 E-MAIL-pradeep.it74@gmail.com C-PROGRAMMING SLIDE-4 Wednesday, September 01, 2010 1 PRADEEP DWIVEDI
  • 2. C-4 TOPIC:- Loop break statement continue statement go to statement Wednesday, September 01, 2010 2 PRADEEP DWIVEDI
  • 3. LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 3 when we want to repeat a particular task again and again that time we use the loop. loop is a control structure that repeats a group of sets in a program. there are three loops in c- while for do while
  • 4. WHILE LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 4 syntax:- while(test-condition) { body of the loop. }
  • 5. WHILE LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 5 the while loop is a entry controlled loop statement. the test condition is evaluated and if the condition is true then the body of loop is executed. after execution of the body the test condition is once again evaluated and if it is true the body is executed once again. this process of repeated execution of the body continues until the test condition finally becomes false and controlled is transferred out of the loop.
  • 6. FLOW CHART(WHILE LOOP) Wednesday, September 01, 2010 PRADEEP DWIVEDI 6
  • 7. PROG13 Wednesday, September 01, 2010 PRADEEP DWIVEDI 7 /* w a p to print 1 to 10 */ #include<stdio.h> #include<conio.h> void main() { inti; clrscr(); i=1; while(i<=10) { printf("%d",i); i++; } getch(); }
  • 8. DO WHILE LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 8 in while loop, makes a test of condition before the loop is executed. therefore, the body of the loop may not be executed at all if the condition is not satisfied at the very first attempt. on a some situations it must be necessary to execute the body of the loop before the test is performed. such situation can be handled with the help of the do statement.
  • 9. DO WHILE LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 9 syntax:- do { body of the loop (true) } while(test-condition);
  • 10. DO WHILE LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 10 in the do while loop it first execute the body and then checks the condition. so if the condition is initially false, it execute atleast once.
  • 11. prog14 Wednesday, September 01, 2010 PRADEEP DWIVEDI 11 /* w.a.p. to print 1 TO 10 digit */ #include<stdio.h> #include<conio.h> void main() { inti; clrscr(); i=1; do { printf("%d",i); i++; } while(i<=10); getch(); }
  • 12. FOR LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 12 It is two type if simple for loop. nested for loop.
  • 13. FOR LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 13 syntax:- for(initialization; test of the condition; increment/decrement) { body of loop }
  • 14. FOR LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 14 in a for loop we always follows the following 4 steps sequentially. initialize the value. test the condition (if it is true) execute the body. increment/decrement the value.
  • 15. FOR LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 15 eg:- for(i=1;i<=10;i++) { printf(“%d”,i); } 1 2 4 false true 3
  • 16. prog15 /* w.a.p. to check the entered number is a prime number or not */ #include<stdio.h> #include<conio.h> #include<process.h> void main() { inti,num; clrscr(); printf("Enter a number"); scanf("%d",&num); for(i=2;i<num;i++) { if(num%i==0) { printf("number is not prime"); getch(); exit(0); } } printf("Number is prime"); getch(); } Wednesday, September 01, 2010 16 PRADEEP DWIVEDI
  • 17. SOME POINTS Wednesday, September 01, 2010 PRADEEP DWIVEDI 17 exit() is a predefine function with the help of it we move out or terminate from the program. it comes from process.h header file. when we use semicolon after the for loop that time it become a self executed loop and it execute when condition become false. we can have more than one initialization and the iteration in a for loop. eg. for(i=1;j=10;i<=10;i++; j--)
  • 18. prog16 Wednesday, September 01, 2010 PRADEEP DWIVEDI 18 /*w.a.p. to calculate factorial of a given number */ #include<stdio.h> #include<conio.h> void main() { intn,i,fac=1; clrscr(); printf("Enter a number whose factorial is found :"); scanf("%d",&n); for(i=n;i>=1;i--) { fac=fac*i; } printf("factorial is:%d",fac); getch(); }
  • 19. prog17 Wednesday, September 01, 2010 PRADEEP DWIVEDI 19 /* w.a.p. to print fabonicai series 1 1 2 3 5 8 13 21 34 55 89 144 223 337 */ #include<stdio.h> #include<conio.h> void main() { int num1,num2; clrscr(); num1=num2=1; printf("%d",num2); while(num2<=200) { printf("%d",num2); num2=num2+num1; num1=num2-num1; } getch(); }
  • 20. NESTED FOR LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 20 nesting of loops, that is, one for statement with in another for statement is allowed in c. eg. for(i=1;i<10;++i) { for(j=1;j<5;++j) { } } outer loop inner loop
  • 21. prog18 /* print this pattern 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 */ #include<stdio.h> #include<conio.h> void main() { inti,j,num; clrscr(); printf("Enter the number :"); scanf("%d",&num); for(i=1;i<=num;i++) { for(j=1;j<=i;j++) { printf("%d",j); } printf(""); } getch(); } Wednesday, September 01, 2010 21 PRADEEP DWIVEDI
  • 22. prog19 /* w.a.p. to print this pattern * * * * * * * * * * * * * * * */ #include<stdio.h> #include<conio.h> void main() { inti,j; clrscr(); for(i=1;i<=5;i++) { for(j=5;j>=i;j--) { printf("* "); } printf(""); } getch(); } Wednesday, September 01, 2010 22 PRADEEP DWIVEDI
  • 23. JUMPING IN THE LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 23 For jumping in the loop we use two statements: break continue
  • 24. THE BREAK STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 24 break is a keyword with the help of it we jump out from the loop. break is only use in the loop and switch case.
  • 25. SYNTAX FOR BREAK STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 25 A. while(………..) { ……. …….. if (condition) break; ……. } exit from loop
  • 26. SYNTAX FOR BREAK STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 26 B. do { …….. if(condition) break; ………. ………. } while(………); exit from loop
  • 27. SYNTAX FOR BREAK STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 27 C. for(……………………………………) { --------- --------- if(condition) break; ------- ------- } ------ exit from loop
  • 28. SYNTAX FOR BREAK STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 28 D. for(……………………………….) { ……… for(……………………..) { if(condition) break; … } .. } exit from inner loop
  • 29. prog20 /*w.a.p. to determine wheather a number is prime or not(using break statement)*/ #include<stdio.h> #include<conio.h> void main() { intnum,i; clrscr(); printf("Enter a number: "); scanf("%d",&num); i=2; while(i<num) { if(num%i==0) { printf("number is not prime"); break; } i++; } if(i==num) printf("number is prime"); getch(); } Wednesday, September 01, 2010 29 PRADEEP DWIVEDI
  • 30. goto STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 30 goto keyword (statement) can transfers the control to any place in a program, it is useful to provide branching with in a loop.
  • 31. SYNTAX OF GOTO STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 31 while(………..) (A) { if(error) goto stop; ……. …… if(condition) gotoabc; ………. ………. abc: …….. } stop: ………… jump with in loop exit from loop
  • 32. SYNTAX OF GOTO STATEMENT Wednesday, September 01, 2010 PRADEEP DWIVEDI 32 for(………………..) (B) { …….. …….. for(…….) { …… ….... if(error) goto error; …….. } ….. } error: ….. …….
  • 33. SOME POINTS Wednesday, September 01, 2010 PRADEEP DWIVEDI 33 in syntax(A) if the condition is satisfied goto statement transfers control to the label abc: stop: abc: error: called label
  • 34. prog21 /* Demo for goto statement */ #include<stdio.h> #include<conio.h> void main() { inti,j,k; clrscr(); for(i=1;i<=3;i++) { for(j=1;j<=3;j++) { for(k=1;k<=3;k++) { if(i==3&&j==3&&k==3) goto out; else printf("%d%d%d",i,j,k); } } } out: printf("out of the loop at last!"); getch(); } Wednesday, September 01, 2010 34 PRADEEP DWIVEDI
  • 35. SKIPPING A PART OF A LOOP Wednesday, September 01, 2010 PRADEEP DWIVEDI 35 For skipping a part of a loop we use continue keyword. the continue statement tells the compiler ,”skip the following statements and continue with next iteration”. the format of continue statement is simply: continue; continue:- is a keyword with the help of that we can move up at the beginning of the loop.
  • 36. SYNTAX Wednesday, September 01, 2010 PRADEEP DWIVEDI 36 A. while(test-condition) { continue; …….. …….. }
  • 37. SYNTAX Wednesday, September 01, 2010 PRADEEP DWIVEDI 37 B. do { ………. ………. if(……..) continue; …….. …….. } while(test-condition);
  • 38. SYNTAX Wednesday, September 01, 2010 PRADEEP DWIVEDI 38 C. for(initialization;test-condition;increment) { ………….. ………….. if(………….) continue; ………. ………. }
  • 39. prog22 Wednesday, September 01, 2010 PRADEEP DWIVEDI 39 /* Demo for break statement */ #include<stdio.h> #include<conio.h> void main() { inti; for(i=0;i<=10;i++) { if(i==5) continue; printf("Er.pradeepdwivedi"); } getch(); }