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

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

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(); }