SlideShare a Scribd company logo
1 of 15
DEPARTMENT OF PHYSICS
M.SC. 1ST SEMESTER (2015-2016)
SUB: COMPUTATIONAL PHYSICS
PRESENTED BY: CHITRA JAIN
SUBMITTED TO : DR. D. K. SHARMA
“LOOP is a programming structure that contains an
executable block of code that repeats (iterates) so long as a
given condition is true or false.” therefore looping statements
also called “ITERATIVE STATEMENTS”.
LOOP
PRETEST
FOR LOOP
WHILE LOOP
POSTEST DO-WHILE LOOP
FOR LOOP
 Pre-test or Entry controlled loop
i.e. conditions are checked first if found true
then and only then code is executed
otherwise
loop gets terminated.
 For loop has three parts:
1. Initialization
2. Condition
3. Increment/ Decrement
 All these three expressions need not be included in for statement. But semicolons must
be present.
for ( ; ; )
SYNTAX:
For (expression 1; expression 2;
exprssion3)
{
Body of the loop
}
 expression 1 : used to initialize loop parameter.
 expression 2 : represent test condition that must
be true for continue execution of loop.
 expression 3 : is update expression that update
the loop parameter (Inc./Dec.)
EXECUTION OF LOOP
For (initialization; condition; Inc./Dec.)
{
statement(s);
}
1
4
EXAMPLE
Q. To find sum of first n natural numbers.
# include <stdio.h>
int main ()
{
int n, count, sum=0;
printf (“enter the value of n n”);
scanf (“%d”,&n);
for (count=1; count<=n; count++)
{
sum=sum+count;
}
printf (“sum=%d”, sum);
getch();
}
output of this program will be as follows:
Enter the value of n
7
sum=28
NESTED LOOP
“ A NESTED LOOP is a loop within a loop i.e. an inner loop within the body of an outer
loop.”
 The inner and outer loops need not be generated by the same type of control
structure.
 It is essential that one loop be completely embedded within the other, there can be
no overlap. Each loop must be controlled by a different index.
 Common use for nested loop is to display data in Rows & columns.
NESTED FOR LOOP STATEMENT
SYNTAX:
For (initialization; condition; Inc./Dec.)
{
for( initialization; condition; Inc./Dec.)
{
statement(s);
}
statements(s);
}
EXAMPLE
# include <stdio.h>
int main()
{
int row,col;
for (row=1; row,=3; row++)
{
for (col=1; col=row; col++)
{
printf(“%d”,row);
}
printf(“n”);
}
getch();
}
output of this program will be as follows:
1
2 2
3 3 3
NESTED WHILE STATEMENT
SYNTAX:
While( condition)
{
while (condition)
{
statement(s);
}
statement(s);
}
NESTED DO- WHILE STATEMENT
SYNTAX:
do
{
statement(s);
do
{
statement(s);
} while (condition);
} while (condition);
Computer

More Related Content

What's hot

What's hot (19)

Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Control statements
Control statementsControl statements
Control statements
 
Fundamentals of Programming Chapter 7
Fundamentals of Programming Chapter 7Fundamentals of Programming Chapter 7
Fundamentals of Programming Chapter 7
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
 
Comp ppt (1)
Comp ppt (1)Comp ppt (1)
Comp ppt (1)
 
Loop c++
Loop c++Loop c++
Loop c++
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
 
Looping Statement And Flow Chart
 Looping Statement And Flow Chart Looping Statement And Flow Chart
Looping Statement And Flow Chart
 
Introduction to php 5
Introduction to php   5Introduction to php   5
Introduction to php 5
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
 
Java loops
Java loopsJava loops
Java loops
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
C++ chapter 4
C++ chapter 4C++ chapter 4
C++ chapter 4
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 6(decision making-looping)
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
Loops c++
Loops c++Loops c++
Loops c++
 

Viewers also liked (20)

Flipped classroom 翻轉教室 karen
Flipped classroom 翻轉教室 karenFlipped classroom 翻轉教室 karen
Flipped classroom 翻轉教室 karen
 
Universidad cesar vallejo lima norte
Universidad cesar vallejo lima norteUniversidad cesar vallejo lima norte
Universidad cesar vallejo lima norte
 
LA TIERRA
LA TIERRALA TIERRA
LA TIERRA
 
Plan de marketing 2015 final
Plan de marketing 2015 finalPlan de marketing 2015 final
Plan de marketing 2015 final
 
Animales
AnimalesAnimales
Animales
 
Los cereales
Los cerealesLos cereales
Los cereales
 
Tipo de variables de PowerDesigner
Tipo de variables de PowerDesignerTipo de variables de PowerDesigner
Tipo de variables de PowerDesigner
 
LA TIERRA
LA TIERRALA TIERRA
LA TIERRA
 
Resume For Siyabonga Nkabinde
Resume For Siyabonga NkabindeResume For Siyabonga Nkabinde
Resume For Siyabonga Nkabinde
 
OFICIO - DEFENSA CIVIL
OFICIO - DEFENSA CIVILOFICIO - DEFENSA CIVIL
OFICIO - DEFENSA CIVIL
 
la etica deontologia
la etica deontologia la etica deontologia
la etica deontologia
 
Derecho informático en nuestra legislación
Derecho informático en nuestra legislaciónDerecho informático en nuestra legislación
Derecho informático en nuestra legislación
 
LA TIERRA
LA TIERRALA TIERRA
LA TIERRA
 
LA TIERRA
LA TIERRALA TIERRA
LA TIERRA
 
LIBRO DIARIO
LIBRO DIARIOLIBRO DIARIO
LIBRO DIARIO
 
LA TIERRA
LA TIERRALA TIERRA
LA TIERRA
 
Proyecto procesadores de texto- Miriam Garcia
Proyecto procesadores de texto- Miriam GarciaProyecto procesadores de texto- Miriam Garcia
Proyecto procesadores de texto- Miriam Garcia
 
La importancia de la educación
La importancia de la educación La importancia de la educación
La importancia de la educación
 
Club S 500. Suplemento 2
Club S 500. Suplemento 2Club S 500. Suplemento 2
Club S 500. Suplemento 2
 
Trabajo conferencias
Trabajo  conferenciasTrabajo  conferencias
Trabajo conferencias
 

Similar to Computer

Repetition Structure
Repetition StructureRepetition Structure
Repetition StructurePRN USM
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingNeeru Mittal
 
Control statements
Control statementsControl statements
Control statementsCutyChhaya
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executionseShikshak
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languageTanmay Modi
 
Chapter 13.1.5
Chapter 13.1.5Chapter 13.1.5
Chapter 13.1.5patcha535
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingPathomchon Sriwilairit
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
2nd year computer science chapter 12 notes
2nd year computer science chapter 12 notes2nd year computer science chapter 12 notes
2nd year computer science chapter 12 notesmuhammadFaheem656405
 
Module 2- Control Structures
Module 2- Control StructuresModule 2- Control Structures
Module 2- Control Structuresnikshaikh786
 
PRESENTATION ON FOR LOOP
PRESENTATION  ON FOR LOOPPRESENTATION  ON FOR LOOP
PRESENTATION ON FOR LOOPFarooq Joyia
 

Similar to Computer (20)

Loops in c
Loops in cLoops in c
Loops in c
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
07 flow control
07   flow control07   flow control
07 flow control
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Iterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop workingIterative control structures, looping, types of loops, loop working
Iterative control structures, looping, types of loops, loop working
 
Control statements
Control statementsControl statements
Control statements
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Chapter 13.1.5
Chapter 13.1.5Chapter 13.1.5
Chapter 13.1.5
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
2nd year computer science chapter 12 notes
2nd year computer science chapter 12 notes2nd year computer science chapter 12 notes
2nd year computer science chapter 12 notes
 
Module 2- Control Structures
Module 2- Control StructuresModule 2- Control Structures
Module 2- Control Structures
 
ICP - Lecture 9
ICP - Lecture 9ICP - Lecture 9
ICP - Lecture 9
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
PRESENTATION ON FOR LOOP
PRESENTATION  ON FOR LOOPPRESENTATION  ON FOR LOOP
PRESENTATION ON FOR LOOP
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 

Recently uploaded

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Recently uploaded (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

Computer

  • 1. DEPARTMENT OF PHYSICS M.SC. 1ST SEMESTER (2015-2016) SUB: COMPUTATIONAL PHYSICS PRESENTED BY: CHITRA JAIN SUBMITTED TO : DR. D. K. SHARMA
  • 2.
  • 3. “LOOP is a programming structure that contains an executable block of code that repeats (iterates) so long as a given condition is true or false.” therefore looping statements also called “ITERATIVE STATEMENTS”.
  • 5. FOR LOOP  Pre-test or Entry controlled loop i.e. conditions are checked first if found true then and only then code is executed otherwise loop gets terminated.  For loop has three parts: 1. Initialization 2. Condition 3. Increment/ Decrement  All these three expressions need not be included in for statement. But semicolons must be present. for ( ; ; )
  • 6. SYNTAX: For (expression 1; expression 2; exprssion3) { Body of the loop }  expression 1 : used to initialize loop parameter.  expression 2 : represent test condition that must be true for continue execution of loop.  expression 3 : is update expression that update the loop parameter (Inc./Dec.)
  • 7. EXECUTION OF LOOP For (initialization; condition; Inc./Dec.) { statement(s); } 1 4
  • 8. EXAMPLE Q. To find sum of first n natural numbers. # include <stdio.h> int main () { int n, count, sum=0; printf (“enter the value of n n”); scanf (“%d”,&n); for (count=1; count<=n; count++) { sum=sum+count; } printf (“sum=%d”, sum); getch(); } output of this program will be as follows: Enter the value of n 7 sum=28
  • 9. NESTED LOOP “ A NESTED LOOP is a loop within a loop i.e. an inner loop within the body of an outer loop.”  The inner and outer loops need not be generated by the same type of control structure.  It is essential that one loop be completely embedded within the other, there can be no overlap. Each loop must be controlled by a different index.  Common use for nested loop is to display data in Rows & columns.
  • 10.
  • 11. NESTED FOR LOOP STATEMENT SYNTAX: For (initialization; condition; Inc./Dec.) { for( initialization; condition; Inc./Dec.) { statement(s); } statements(s); }
  • 12. EXAMPLE # include <stdio.h> int main() { int row,col; for (row=1; row,=3; row++) { for (col=1; col=row; col++) { printf(“%d”,row); } printf(“n”); } getch(); } output of this program will be as follows: 1 2 2 3 3 3
  • 13. NESTED WHILE STATEMENT SYNTAX: While( condition) { while (condition) { statement(s); } statement(s); }
  • 14. NESTED DO- WHILE STATEMENT SYNTAX: do { statement(s); do { statement(s); } while (condition); } while (condition);