SlideShare a Scribd company logo
Electrical Engineering Department
Loop in C
Properties &
Applications
By Emroz Sardar
Electrical Engineering Department
03
02
01
04
Details,
History & Advantages
Introduction
Types of Loops, Flowcharts &
Practical Use
TABLE OF CONTENTS
Outputs & Conclusion
Electrical Engineering Department
What is a Loop ?
Looping Statements in C execute the sequence
of statements many times until the stated
condition becomes false. A loop in C consists of
two parts, a body of a loop and a control
statement. The control statement is a
combination of some conditions that direct the
body of the loop to execute until the specified
condition becomes false. The purpose of the C
loop is to repeat the same code a number of
times.
Electrical Engineering Department
LOOP is nothing but a language that precisely captures primitive recursive
functions. The only operations supported in the language are assignment,
addition, and looping a number of times that is fixed before loop execution
starts.
The LOOP language was introduced in 1967 by Albert R. Meyer and Dennis M.
Ritchie. Meyer and Ritchie showed the correspondence between the LOOP
language and primitive recursive functions. Dennis M. Ritchie mainly
formulated the LOOP language.
It is known that the FOR loop has been part of the C language since the early
1970s (or late 1960s) and was developed by John Backus, but the DO loop
has been a part of Fortran since it was developed in the mid-1950s by John
Backus and his team at IBM.
The name for-loop comes from the word for, which is used as the keyword in
many programming languages to introduce a for-loop. The term in English
dates to ALGOL 58 and was popularized in the influential later ALGOL 60.
The loop body is executed "for" the given values of the loop variable, though
this is more explicit in the ALGOL version of the statement, in which a list of
possible values and/or increments can be specified.
(There’s no relevant name or origin related history for while & do while loop)
History of LOOPs
Electrical Engineering Department
Advantages of LOOPs
● It provides code reusability.
● Using loops, we do not need to write the same code
again and again.
● Using loops, we can traverse over the elements of
data structures (array or linked lists).
Electrical Engineering Department
In C language, there are 3 types of LOOP ::
● FOR LOOP
● WHILE LOOP
● DO-WHILE LOOP
TYPES OF LOOPS
Electrical Engineering Department
LOOPS
Entry Controlled
Exit Controlled
For LOOP
While LOOP
Do While
Electrical Engineering Department
In programming, LOOPs are considered as controlled
statements that can regulate the flow of the program
execution. They use a conditional expression in order to
decide to what extent a particular block should be
repeated. Every loop consists of two sections, loop body
and control statement.
Based on the position of these two sections, loop
execution can be handled in two ways that are at the
entry-level and exit-level.
So, loops can be categorized into two types:
● Entry controlled loop: When a condition is evaluated
at the beginning of the loop.
● Exit controlled loop: When a condition is evaluated at
the end of the loop.
Electrical Engineering Department
Entry Controlled Loop: An entry control loop checks
condition at entry level (at beginning), that’s why it is
termed as entry control loop. It is a type of loop in which
the condition is checked first and then after the loop
body executed. For loop and while loop fall in this
category. If the condition is true, the loop body would be
executed otherwise, the loop would be terminated.
Exit Control Loop: An exit control loop checks condition
at exit level (in the end), that’s why it is termed as exit
control loop. Oppose to Entry controlled loop, it is a loop
in which condition is checked after the execution of the
loop body. Do while loop is the example. The loop body
would be executed at least once, no matter if the test
condition is true or false.
Electrical Engineering Department
FOR LOOP
● A For loop is the most efficient loop structure in C
programming. It allows us to write a loop that needs
to execute a specific number of times. The for loop in
C language is used to iterate the statements or a part
of the program several times. It is frequently used to
traverse the data structures like the array and linked
list.
● Syntax of for loop in C
The syntax of for loop in c language is given below:
for( initialization; condition; increment/decrement)
{
//code to be executed
}
Electrical Engineering Department
How for loop works?
● The initialization statement is executed only once.
● Then, the test expression is evaluated. If the test
expression is evaluated to false, the for loop is
terminated.
● However, if the test expression is evaluated to true,
statements inside the body of the for loop are
executed, and the update expression is updated.
● Again the test expression is evaluated.
*This process goes on until the test expression is false.
When the test expression is false, the loop terminates.
Electrical Engineering Department
For LOOP
FlowChart
Electrical Engineering Department
A While Loop is used to repeat a specific block of code an
unknown number of times, until a condition is met. For
example, if we want to ask a user for a number between 1
and 10, we don't know how many times the user may enter
a larger number, so we keep asking "while the number is
not between 1 and 10". If we (or the computer) knows
exactly how many times to execute a section of code
(such as shuffling a deck of cards) we use a for loop.
The syntax of while loop in c language is given below:
while (condition){
//code to be executed
}
Flowchart and Example of while loop
While LOOP
Electrical Engineering Department
Why While Loops?
● Like all loops, "while loops" execute
blocks of code over and over again.
● The advantage to a while loop is that
it will go (repeat) as often as
necessary to accomplish its goal.
Electrical Engineering Department
How while Loop works?
In while loop, condition is evaluated first
and if it returns true then the statements
inside while loop execute, this happens
repeatedly until the condition returns
false. When condition returns false, the
control comes out of loop and jumps to the
next statement in the program after while
loop.
Electrical Engineering Department
while LOOP
FlowChart
Electrical Engineering Department
The do...while statement creates a loop that executes a specified
statement until the test condition evaluates to false. The condition is
evaluated after executing the statement, resulting in the specified
statement executing at least once.
The syntax for do…while loop is stated below:
do
{
//code to be executed
}while(condition);
● Unlike for and while loops, that test the loop condition at the top of
the loop, the do...while loop checks its condition at the bottom of
the loop.
● A do...while loop is similar to a while loop, except that a do...while
loop is guaranteed to execute at least one time, where only while
loop executes the target statement, repeatedly.
Do while LOOP
Electrical Engineering Department
How Do...While loop works
The conditional expression appears at the end of the
loop, so the statement(s) in the loop executes once
before the condition is tested.
If the condition is true, the flow of control jumps back
up to do, and the statement(s) in the loop executes
again. This process repeats until the given condition
becomes false.
Electrical Engineering Department
Do while LOOP
FlowChart
Electrical Engineering Department
DIFFERENCE BETWEEN WHILE LOOP AND DO WHILE LOOP
● Condition is checked first then
statement(s) is executed.
● It might occur statement(s) is
executed zero times, If condition
is false..
● No semicolon at the end of
while.
while(condition)
● If there is a single statement,
brackets are not required.
● Variable in condition is initialized
before the execution of loop.
● while loop is entry controlled
loop.
● while (condition)
{ statement(s); }
● Statement(s) is executed at
least once, thereafter condition
is checked.
● At least once the statement(s) is
executed.
● Semicolon at the end of while.
while(condition);
● Brackets are always required.
● variable may be initialized
before or within the loop.
● do-while loop is exit controlled
loop.
● do { statement(s); }
while(condition);
While loop Do-while loop
Electrical Engineering Department
NESTed LOOP
A nested loop has one loop inside of another. These are typically
used for working with two dimensions such as printing stars in
rows and columns the syntax are shown below. When a loop is
nested inside another loop, the inner loop runs many times inside
the outer loop. In each iteration of the outer loop, the inner loop
will be re-started. The inner loop must finish all of its iterations
before the outer loop can continue to its next iteration.
Syntax of Nested loop
OuterLoop
{
InnerLoop
{
// inner loop statements.
}
// outer loop statements.
}
Electrical Engineering Department
NESTed LOOP
FlowChart
Electrical Engineering Department
Infinitive
loop
To make a for loop infinite,
we need not give any
expression in the syntax.
Instead of that, we can put
two semicolons to validate
the syntax of the for loop. It
will work as an infinite for
loop.
For example :
#include <stdio.h>
void main()
{ int i = 10;
for( ; ;)
{
printf("%dn",i);
}
}
In while loop, when the
condition passes and if it is
true , it runs infinite number
of times.
For example :
#include <stdio.h>
void main()
{ int i = 10;
while(1)
{
printf("%dt",i);
i++;
}
}
The do-while loop will run
infinite times if we pass any
non-zero value as the
conditional expression.
For example :
#include <stdio.h>
void main()
{ int i = 10;
do
{
printf("%dt",i);
i++;
} while(i);
}
Electrical Engineering Department
BREAK AND CONTINUE STATEMENTS
● When a break statement is
encountered inside a loop, the loop
is immediately terminated and the
program control resumes at the next
statement following the loop.
For the for loop, continue statement
causes the conditional test and increment
portions of the loop to execute. For the
while and do...while loops, continue
statement causes the program control to
pass to the conditional tests.
true
Electrical Engineering Department
Practical Use
Real World Examples of Loop
● Software of the ATM machine is in a loop to process
transaction after transaction until you acknowledge that
you have no more to do.
● Software program in a mobile device allows user to unlock
the mobile with 5 password attempts. After that it resets
mobile device.
● You put your favorite song on a repeat mode. It is also a
loop.
● You want to run a particular analysis on each column of
your data set.
Electrical Engineering Department
FlowChart for
Digital Clock
For LOOP
Our Example
Electrical Engineering Department
*Fast Forwarded
Electrical Engineering Department
CONCLUSION
Looping in C or in any programming language is one of
the key concepts. There are generally two types that are
entry controlled and exit controlled loop. The loops or
statement blocks execute a number of times until the
condition becomes false.
❖ Advantages
● Using loops, we do not need to write the same code
again and again.
● Using loops, we can traverse over the elements of
data structures (array or linked lists).
● It provides code reusability.
Electrical Engineering Department
REFERENCE
❖ https://www.guru99.com/c-loop-statement.html
❖ https://www.programiz.com/c-programming/c-for-loop
❖ https://www.cs.utah.edu/~germain/PPS/Topics/while_loops.html
❖ https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Statements/do...while
❖ https://www.geeksforgeeks.org/difference-between-while-and-do-while-loop-in-
c-c-java/
❖ https://www.tutorialspoint.com/cprogramming/c_break_statement.htm
Electrical Engineering Department
Do you have any questions?
supermanemroz@gmail.com
+91 9804226160
AeroSoft.in
THANKS!

More Related Content

What's hot

Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
Mahantesh Devoor
 
Nested loop in C language
Nested loop in C languageNested loop in C language
Nested loop in C language
ErumShammim
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
CHANDAN KUMAR
 
Friend function in c++
Friend function in c++ Friend function in c++
Friend function in c++
University of Madras
 
Switch case in C++
Switch case in C++Switch case in C++
Switch case in C++
Barani Govindarajan
 
C tokens
C tokensC tokens
C tokens
Manu1325
 
Pseudocode
PseudocodePseudocode
Pseudocode
grahamwell
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
Mushiii
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
Appili Vamsi Krishna
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Break and continue
Break and continueBreak and continue
Break and continue
Frijo Francis
 
Conditional operators
Conditional operatorsConditional operators
Conditional operators
BU
 
String in programming language in c or c++
 String in programming language  in c or c++  String in programming language  in c or c++
String in programming language in c or c++
Samsil Arefin
 
Loops c++
Loops c++Loops c++
Loops c++
Shivani Singh
 
Loop(for, while, do while) condition Presentation
Loop(for, while, do while) condition PresentationLoop(for, while, do while) condition Presentation
Loop(for, while, do while) condition Presentation
Badrul Alam
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdfEASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
sudhakargeruganti
 
Computer Language Translator
Computer Language TranslatorComputer Language Translator
Computer Language Translator
Ranjeet Kumar
 
C programming
C programmingC programming
C programming
Jigarthacker
 
How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program
Leela Koneru
 

What's hot (20)

Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
Nested loop in C language
Nested loop in C languageNested loop in C language
Nested loop in C language
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
 
Friend function in c++
Friend function in c++ Friend function in c++
Friend function in c++
 
Switch case in C++
Switch case in C++Switch case in C++
Switch case in C++
 
C tokens
C tokensC tokens
C tokens
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Break and continue
Break and continueBreak and continue
Break and continue
 
Conditional operators
Conditional operatorsConditional operators
Conditional operators
 
String in programming language in c or c++
 String in programming language  in c or c++  String in programming language  in c or c++
String in programming language in c or c++
 
Loops c++
Loops c++Loops c++
Loops c++
 
Loop(for, while, do while) condition Presentation
Loop(for, while, do while) condition PresentationLoop(for, while, do while) condition Presentation
Loop(for, while, do while) condition Presentation
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdfEASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
EASY UNDERSTANDING OF FILES IN C LANGUAGE.pdf
 
Computer Language Translator
Computer Language TranslatorComputer Language Translator
Computer Language Translator
 
C programming
C programmingC programming
C programming
 
How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program
 

Similar to Loop in C Properties & Applications

Cse lecture-7-c loop
Cse lecture-7-c loopCse lecture-7-c loop
Cse lecture-7-c loop
FarshidKhan
 
Loops
LoopsLoops
Loops
LoopsLoops
C language 2
C language 2C language 2
C language 2
Arafat Bin Reza
 
Loop structures
Loop structuresLoop structures
Loop structures
tazeem sana
 
Cpp loop types
Cpp loop typesCpp loop types
Cpp loop types
Rj Baculo
 
R loops
R   loopsR   loops
Computer programming 2 Lesson 8
Computer programming 2  Lesson 8Computer programming 2  Lesson 8
Computer programming 2 Lesson 8
MLG College of Learning, Inc
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
SURBHI SAROHA
 
DECISION MAKING.pptx
DECISION MAKING.pptxDECISION MAKING.pptx
DECISION MAKING.pptx
Ayshwarya Baburam
 
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRLoops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Krishna Raj
 
LOOPING IN C- PROGRAMMING.pptx
LOOPING IN C- PROGRAMMING.pptxLOOPING IN C- PROGRAMMING.pptx
LOOPING IN C- PROGRAMMING.pptx
AFANJIPHILL
 
python.pptx
python.pptxpython.pptx
python.pptx
Poornima116356
 
Loops in c
Loops in cLoops in c
Loops in c
RekhaBudhwar
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
Niket Chandrawanshi
 
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
muhammadFaheem656405
 
prt123.pptx
prt123.pptxprt123.pptx
prt123.pptx
ASADKS
 
Chapter 12 Computer Science ( ICS 12).pdf
Chapter 12 Computer Science ( ICS 12).pdfChapter 12 Computer Science ( ICS 12).pdf
Chapter 12 Computer Science ( ICS 12).pdf
AamirShahzad527024
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
Eng Teong Cheah
 
Do While Repetition Structure
Do While Repetition StructureDo While Repetition Structure
Do While Repetition Structure
Shahzu2
 

Similar to Loop in C Properties & Applications (20)

Cse lecture-7-c loop
Cse lecture-7-c loopCse lecture-7-c loop
Cse lecture-7-c loop
 
Loops
LoopsLoops
Loops
 
Loops
LoopsLoops
Loops
 
C language 2
C language 2C language 2
C language 2
 
Loop structures
Loop structuresLoop structures
Loop structures
 
Cpp loop types
Cpp loop typesCpp loop types
Cpp loop types
 
R loops
R   loopsR   loops
R loops
 
Computer programming 2 Lesson 8
Computer programming 2  Lesson 8Computer programming 2  Lesson 8
Computer programming 2 Lesson 8
 
C language (Part 2)
C language (Part 2)C language (Part 2)
C language (Part 2)
 
DECISION MAKING.pptx
DECISION MAKING.pptxDECISION MAKING.pptx
DECISION MAKING.pptx
 
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRLoops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
 
LOOPING IN C- PROGRAMMING.pptx
LOOPING IN C- PROGRAMMING.pptxLOOPING IN C- PROGRAMMING.pptx
LOOPING IN C- PROGRAMMING.pptx
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Loops in c
Loops in cLoops in c
Loops in c
 
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
 
prt123.pptx
prt123.pptxprt123.pptx
prt123.pptx
 
Chapter 12 Computer Science ( ICS 12).pdf
Chapter 12 Computer Science ( ICS 12).pdfChapter 12 Computer Science ( ICS 12).pdf
Chapter 12 Computer Science ( ICS 12).pdf
 
Learn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & LoopsLearn C# Programming - Decision Making & Loops
Learn C# Programming - Decision Making & Loops
 
Do While Repetition Structure
Do While Repetition StructureDo While Repetition Structure
Do While Repetition Structure
 

Recently uploaded

Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 

Recently uploaded (20)

Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 

Loop in C Properties & Applications

  • 1. Electrical Engineering Department Loop in C Properties & Applications By Emroz Sardar
  • 2. Electrical Engineering Department 03 02 01 04 Details, History & Advantages Introduction Types of Loops, Flowcharts & Practical Use TABLE OF CONTENTS Outputs & Conclusion
  • 3. Electrical Engineering Department What is a Loop ? Looping Statements in C execute the sequence of statements many times until the stated condition becomes false. A loop in C consists of two parts, a body of a loop and a control statement. The control statement is a combination of some conditions that direct the body of the loop to execute until the specified condition becomes false. The purpose of the C loop is to repeat the same code a number of times.
  • 4. Electrical Engineering Department LOOP is nothing but a language that precisely captures primitive recursive functions. The only operations supported in the language are assignment, addition, and looping a number of times that is fixed before loop execution starts. The LOOP language was introduced in 1967 by Albert R. Meyer and Dennis M. Ritchie. Meyer and Ritchie showed the correspondence between the LOOP language and primitive recursive functions. Dennis M. Ritchie mainly formulated the LOOP language. It is known that the FOR loop has been part of the C language since the early 1970s (or late 1960s) and was developed by John Backus, but the DO loop has been a part of Fortran since it was developed in the mid-1950s by John Backus and his team at IBM. The name for-loop comes from the word for, which is used as the keyword in many programming languages to introduce a for-loop. The term in English dates to ALGOL 58 and was popularized in the influential later ALGOL 60. The loop body is executed "for" the given values of the loop variable, though this is more explicit in the ALGOL version of the statement, in which a list of possible values and/or increments can be specified. (There’s no relevant name or origin related history for while & do while loop) History of LOOPs
  • 5. Electrical Engineering Department Advantages of LOOPs ● It provides code reusability. ● Using loops, we do not need to write the same code again and again. ● Using loops, we can traverse over the elements of data structures (array or linked lists).
  • 6. Electrical Engineering Department In C language, there are 3 types of LOOP :: ● FOR LOOP ● WHILE LOOP ● DO-WHILE LOOP TYPES OF LOOPS
  • 7. Electrical Engineering Department LOOPS Entry Controlled Exit Controlled For LOOP While LOOP Do While
  • 8. Electrical Engineering Department In programming, LOOPs are considered as controlled statements that can regulate the flow of the program execution. They use a conditional expression in order to decide to what extent a particular block should be repeated. Every loop consists of two sections, loop body and control statement. Based on the position of these two sections, loop execution can be handled in two ways that are at the entry-level and exit-level. So, loops can be categorized into two types: ● Entry controlled loop: When a condition is evaluated at the beginning of the loop. ● Exit controlled loop: When a condition is evaluated at the end of the loop.
  • 9. Electrical Engineering Department Entry Controlled Loop: An entry control loop checks condition at entry level (at beginning), that’s why it is termed as entry control loop. It is a type of loop in which the condition is checked first and then after the loop body executed. For loop and while loop fall in this category. If the condition is true, the loop body would be executed otherwise, the loop would be terminated. Exit Control Loop: An exit control loop checks condition at exit level (in the end), that’s why it is termed as exit control loop. Oppose to Entry controlled loop, it is a loop in which condition is checked after the execution of the loop body. Do while loop is the example. The loop body would be executed at least once, no matter if the test condition is true or false.
  • 10. Electrical Engineering Department FOR LOOP ● A For loop is the most efficient loop structure in C programming. It allows us to write a loop that needs to execute a specific number of times. The for loop in C language is used to iterate the statements or a part of the program several times. It is frequently used to traverse the data structures like the array and linked list. ● Syntax of for loop in C The syntax of for loop in c language is given below: for( initialization; condition; increment/decrement) { //code to be executed }
  • 11. Electrical Engineering Department How for loop works? ● The initialization statement is executed only once. ● Then, the test expression is evaluated. If the test expression is evaluated to false, the for loop is terminated. ● However, if the test expression is evaluated to true, statements inside the body of the for loop are executed, and the update expression is updated. ● Again the test expression is evaluated. *This process goes on until the test expression is false. When the test expression is false, the loop terminates.
  • 13. Electrical Engineering Department A While Loop is used to repeat a specific block of code an unknown number of times, until a condition is met. For example, if we want to ask a user for a number between 1 and 10, we don't know how many times the user may enter a larger number, so we keep asking "while the number is not between 1 and 10". If we (or the computer) knows exactly how many times to execute a section of code (such as shuffling a deck of cards) we use a for loop. The syntax of while loop in c language is given below: while (condition){ //code to be executed } Flowchart and Example of while loop While LOOP
  • 14. Electrical Engineering Department Why While Loops? ● Like all loops, "while loops" execute blocks of code over and over again. ● The advantage to a while loop is that it will go (repeat) as often as necessary to accomplish its goal.
  • 15. Electrical Engineering Department How while Loop works? In while loop, condition is evaluated first and if it returns true then the statements inside while loop execute, this happens repeatedly until the condition returns false. When condition returns false, the control comes out of loop and jumps to the next statement in the program after while loop.
  • 17. Electrical Engineering Department The do...while statement creates a loop that executes a specified statement until the test condition evaluates to false. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once. The syntax for do…while loop is stated below: do { //code to be executed }while(condition); ● Unlike for and while loops, that test the loop condition at the top of the loop, the do...while loop checks its condition at the bottom of the loop. ● A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time, where only while loop executes the target statement, repeatedly. Do while LOOP
  • 18. Electrical Engineering Department How Do...While loop works The conditional expression appears at the end of the loop, so the statement(s) in the loop executes once before the condition is tested. If the condition is true, the flow of control jumps back up to do, and the statement(s) in the loop executes again. This process repeats until the given condition becomes false.
  • 19. Electrical Engineering Department Do while LOOP FlowChart
  • 20. Electrical Engineering Department DIFFERENCE BETWEEN WHILE LOOP AND DO WHILE LOOP ● Condition is checked first then statement(s) is executed. ● It might occur statement(s) is executed zero times, If condition is false.. ● No semicolon at the end of while. while(condition) ● If there is a single statement, brackets are not required. ● Variable in condition is initialized before the execution of loop. ● while loop is entry controlled loop. ● while (condition) { statement(s); } ● Statement(s) is executed at least once, thereafter condition is checked. ● At least once the statement(s) is executed. ● Semicolon at the end of while. while(condition); ● Brackets are always required. ● variable may be initialized before or within the loop. ● do-while loop is exit controlled loop. ● do { statement(s); } while(condition); While loop Do-while loop
  • 21. Electrical Engineering Department NESTed LOOP A nested loop has one loop inside of another. These are typically used for working with two dimensions such as printing stars in rows and columns the syntax are shown below. When a loop is nested inside another loop, the inner loop runs many times inside the outer loop. In each iteration of the outer loop, the inner loop will be re-started. The inner loop must finish all of its iterations before the outer loop can continue to its next iteration. Syntax of Nested loop OuterLoop { InnerLoop { // inner loop statements. } // outer loop statements. }
  • 23. Electrical Engineering Department Infinitive loop To make a for loop infinite, we need not give any expression in the syntax. Instead of that, we can put two semicolons to validate the syntax of the for loop. It will work as an infinite for loop. For example : #include <stdio.h> void main() { int i = 10; for( ; ;) { printf("%dn",i); } } In while loop, when the condition passes and if it is true , it runs infinite number of times. For example : #include <stdio.h> void main() { int i = 10; while(1) { printf("%dt",i); i++; } } The do-while loop will run infinite times if we pass any non-zero value as the conditional expression. For example : #include <stdio.h> void main() { int i = 10; do { printf("%dt",i); i++; } while(i); }
  • 24. Electrical Engineering Department BREAK AND CONTINUE STATEMENTS ● When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop. For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while and do...while loops, continue statement causes the program control to pass to the conditional tests. true
  • 25. Electrical Engineering Department Practical Use Real World Examples of Loop ● Software of the ATM machine is in a loop to process transaction after transaction until you acknowledge that you have no more to do. ● Software program in a mobile device allows user to unlock the mobile with 5 password attempts. After that it resets mobile device. ● You put your favorite song on a repeat mode. It is also a loop. ● You want to run a particular analysis on each column of your data set.
  • 26. Electrical Engineering Department FlowChart for Digital Clock For LOOP Our Example
  • 28. Electrical Engineering Department CONCLUSION Looping in C or in any programming language is one of the key concepts. There are generally two types that are entry controlled and exit controlled loop. The loops or statement blocks execute a number of times until the condition becomes false. ❖ Advantages ● Using loops, we do not need to write the same code again and again. ● Using loops, we can traverse over the elements of data structures (array or linked lists). ● It provides code reusability.
  • 29. Electrical Engineering Department REFERENCE ❖ https://www.guru99.com/c-loop-statement.html ❖ https://www.programiz.com/c-programming/c-for-loop ❖ https://www.cs.utah.edu/~germain/PPS/Topics/while_loops.html ❖ https://developer.mozilla.org/en- US/docs/Web/JavaScript/Reference/Statements/do...while ❖ https://www.geeksforgeeks.org/difference-between-while-and-do-while-loop-in- c-c-java/ ❖ https://www.tutorialspoint.com/cprogramming/c_break_statement.htm
  • 30. Electrical Engineering Department Do you have any questions? supermanemroz@gmail.com +91 9804226160 AeroSoft.in THANKS!