SlideShare a Scribd company logo
2
‘ C’ and Iterative Logic To apply the Iterative logic we have three control structures in ‘C’ Language as listed below, for   Loop while  loop do while  loop Ch – 8 For Loop By Abdul Ghaffar Khan
Most read
3
The  for  Loop: for  loop is used when a process is to repeat a fixed number of times. The structure of a  for  loop is as follows for(expression_l; expression_2; expression_3) any_instruction; Or for(expression_l; expression_2; expression_3) { body-of-IOOP } Ch – 8 For Loop By Abdul Ghaffar Khan
Most read
4
Order of execution When the loop is started normally a control variable is initialized by executing expression_l. expression_2 is tested if it is false then control is transferred outside the loop otherwise do next step 3 Body of loop is executed. Value of control variable is altered by expression_3 Steps (2) to (4) are repeated until condition becomes false Ch – 8 For Loop By Abdul Ghaffar Khan for(exl; ex2; ex3) {   body-of-IOOP }
Most read
The wizards of For Loop A Lecture By Abdul Ghaffar Khan
‘ C’ and Iterative Logic To apply the Iterative logic we have three control structures in ‘C’ Language as listed below, for   Loop while  loop do while  loop Ch – 8 For Loop By Abdul Ghaffar Khan
The  for  Loop: for  loop is used when a process is to repeat a fixed number of times. The structure of a  for  loop is as follows for(expression_l; expression_2; expression_3) any_instruction; Or for(expression_l; expression_2; expression_3) { body-of-IOOP } Ch – 8 For Loop By Abdul Ghaffar Khan
Order of execution When the loop is started normally a control variable is initialized by executing expression_l. expression_2 is tested if it is false then control is transferred outside the loop otherwise do next step 3 Body of loop is executed. Value of control variable is altered by expression_3 Steps (2) to (4) are repeated until condition becomes false Ch – 8 For Loop By Abdul Ghaffar Khan for(exl; ex2; ex3) {   body-of-IOOP }
Example 8.1  ( Print 10 natural numbers) Ch – 8 For Loop By Abdul Ghaffar Khan main()  {  int NBR; clrscr();  for(NBR=l; NBR<=10; ++NBR)  printf(&quot;%d &quot;,NBR);  getch()  }  Output: 2 3 4 5 6 7  8 9  10
Example 8.2  ( print a table ) main() { int n, p, i= 0; clrscr(); printf(&quot;Enter a number whose table is to print &quot;); scanf(&quot;%d&quot;, &n); printf(&quot;Table of %d \n&quot;, n); for (i=1; i<=12; ++i) { p = i* n; printf(&quot;%d * %4 = %d\n&quot; n, i, p ); . } getch(); } Ch – 8 For Loop By Abdul Ghaffar Khan Output Enter a number whose table is to print 6 6  *  1 = 6 6 *  2 = 12 6 *  3 =18 6  *  4 = 24 6  *  5 = 30 6  *  6 = 36 6  *  7 = 42 6  *  8 = 48  6  *  9 = 54 6  * 10 = 60  6  * 11 = 66 6  * 12 = 72
Example 8.3 Write down a program to generate the following output Ch – 8 For Loop By Abdul Ghaffar Khan C8 lower left corner BC lower right corner
Example 8.3 void main(void) { int x, y; clrscr(); . printf (&quot;\xc9&quot;); for (x=1; x<72 ; ++x) { printf(&quot;\xcd&quot;) ; } printf(&quot;\xBB\n&quot;);  // drawing vertical lines  for (x=1;x<10;++x) { if (x==5) printf(&quot;\xBA\t\t\tWelcome To Learning C\t\t\t\t\xBA\n&quot;); printf(&quot;\xBA\t\t\t\t\t\t\t\t\t\xBA\n&quot;); } Ch – 8 For Loop By Abdul Ghaffar Khan printf(&quot;\xC8&quot;); // drawing bottom line  for (x=1;x<72;++x) {    printf(&quot;\xcd&quot;); } printf(&quot;\xBC\n&quot;) ; getch(); }
Multiple assignments in the for loop We can use more than one  initialization  statement and more than one  Increment decrement  statements however only  one condition  is allowed within a for loop. When used multiple assignments or increment commas separate each statement. for( assignment I, asslgnment2; Condition; Increment1, intement2) . { body of loop } Ch – 8 For Loop By Abdul Ghaffar Khan
Example 8.3 #include<stdio.h> #include<conio.h> void main(void) { int x, y; clrscr(); for(x = 1, y= 10; x<= 10; ++x, --y) printf(&quot;x = %d\tY = %d\n&quot;,x,y); getch(); ; }  Ch – 8 For Loop By Abdul Ghaffar Khan Output: X= 1 Y = 10 X= 2  Y = 9  X= 3  Y = 8 X= 4  Y = 7 X=5  Y = 6 X=6  Y = 5 X=7 Y = 4 X=8  Y =3 X=9  Y =2 X=10  Y =1
The break statement break statement is used to take immediate exit from the for loop. When break statement is executed the control immediately be transferred to the first statement following the for loop.  Ch – 8 For Loop By Abdul Ghaffar Khan main() { for( exp_l ; exp_2; exp_3) { statement1; statement2; if( condition) beak; statement3; statement4; } statement5; statement6; }
The continue statement Continue statement is used to skip the remaining statement in a loop this statement immediately transfer the control to the increment or decrement expression in the loop Ch – 8 For Loop By Abdul Ghaffar Khan main() { for( exp_l ; exp_2;exp_3) { statement 1; statement 2.; if( condition) continue; statement3; statement4; }  statement5;. statement6; }
Nested for loop: When a for loop is completely embedded ( enclosed) within another for loop, the structure is called nested for loop,  Ch – 8 For Loop By Abdul Ghaffar Khan for ( exp1 ; condition;exp2) { body-of-loop 1 for( exp3; condition2;exp4) { body-of-loop2 } }
Example 8.4  ( Factorials) void main(void) { int i,j; long fact; . clrscr(); for (i =1;i<=7;++i) {   fact=l.   for (j=i; j> I; --j)   {   fact *= j;   } printf(&quot;\n%d! = %d\n&quot;,i,fact); } getch(); } Ch – 8 For Loop By Abdul Ghaffar Khan Output: 1! = I 2! =2 3! =6 4! =24 5! = 120 6! = 720 7! = 5040
Example 8.5  ( Stars) void main(void) { int I,j; clrscr(); for (i =1;i<=10;++i) { for 0= 1; j<=i ; ++j) { printf('*'); , } printf(&quot;\n&quot;);  }  getch(); } Ch – 8 For Loop By Abdul Ghaffar Khan Output: *  ** *** **** ***** ****** ******* ******** ********* **********

More Related Content

What's hot (20)

Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
Priyansh Thakar
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
Vishvesh Jasani
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
Introduction to programming languages
Introduction to programming languagesIntroduction to programming languages
Introduction to programming languages
Sayed Mahmoud AbdEl Rahman
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
lavanya marichamy
 
Types of function call
Types of function callTypes of function call
Types of function call
ArijitDhali
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
Prof. Dr. K. Adisesha
 
Clanguage
ClanguageClanguage
Clanguage
Vidyacenter
 
The Loops
The LoopsThe Loops
The Loops
Krishma Parekh
 
Chap 6(decision making-looping)
Chap 6(decision making-looping)Chap 6(decision making-looping)
Chap 6(decision making-looping)
Bangabandhu Sheikh Mujibur Rahman Science and Technology University
 
Seminar report On Python
Seminar report On PythonSeminar report On Python
Seminar report On Python
Shivam Gupta
 
Recursion in c++
Recursion in c++Recursion in c++
Recursion in c++
Abdul Rehman
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
Rabin BK
 
C Programming Project
C Programming ProjectC Programming Project
C Programming Project
Vijayananda Mohire
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
SudhanshuVijay3
 
linux commands.pdf
linux commands.pdflinux commands.pdf
linux commands.pdf
amitkamble79
 
c++ lab manual
c++ lab manualc++ lab manual
c++ lab manual
Shrunkhala Wankhede
 
Python
PythonPython
Python
Shivam Gupta
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
Tanmay Modi
 
File handling in c
File handling in cFile handling in c
File handling in c
aakanksha s
 

Similar to For Loop (20)

Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
Hattori Sidek
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
sana shaikh
 
C.pdf
C.pdfC.pdf
C.pdf
KrithickAndrews1
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
Vikash Dhal
 
Loops in c
Loops in cLoops in c
Loops in c
shubhampandav3
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
rohassanie
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
kapil078
 
Programming basics
Programming basicsProgramming basics
Programming basics
246paa
 
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdfPROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
JNTUK KAKINADA
 
Unit 5 Control Structures.pptx
Unit 5 Control Structures.pptxUnit 5 Control Structures.pptx
Unit 5 Control Structures.pptx
Precise Mya
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
Indraprastha Institute of Information Technology
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
Pathomchon Sriwilairit
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
Shipra Swati
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
Vikram Nandini
 
Looping statements
Looping statementsLooping statements
Looping statements
Chukka Nikhil Chakravarthy
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
Zohaib Ahmed
 
Looping
LoopingLooping
Looping
Kathmandu University
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
Hemantha Kulathilake
 
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 2.pdf
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 2.pdfC_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 2.pdf
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 2.pdf
amanpathak160605
 
Module 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdfModule 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdf
SudipDebnath20
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
sana shaikh
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
Vikash Dhal
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
rohassanie
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
kapil078
 
Programming basics
Programming basicsProgramming basics
Programming basics
246paa
 
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdfPROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
JNTUK KAKINADA
 
Unit 5 Control Structures.pptx
Unit 5 Control Structures.pptxUnit 5 Control Structures.pptx
Unit 5 Control Structures.pptx
Precise Mya
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
Pathomchon Sriwilairit
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
Shipra Swati
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
Zohaib Ahmed
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
Hemantha Kulathilake
 
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 2.pdf
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 2.pdfC_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 2.pdf
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 2.pdf
amanpathak160605
 
Module 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdfModule 2 - Control Structures c programming.pptm.pdf
Module 2 - Control Structures c programming.pptm.pdf
SudipDebnath20
 
Ad

More from Ghaffar Khan (20)

World is beautiful ... ...
World is beautiful ... ...World is beautiful ... ...
World is beautiful ... ...
Ghaffar Khan
 
My Presentation On Ajax
My Presentation On AjaxMy Presentation On Ajax
My Presentation On Ajax
Ghaffar Khan
 
Sorting
SortingSorting
Sorting
Ghaffar Khan
 
How A Computer Works
How A Computer WorksHow A Computer Works
How A Computer Works
Ghaffar Khan
 
Exponential and Logarthmic funtions
Exponential and Logarthmic funtionsExponential and Logarthmic funtions
Exponential and Logarthmic funtions
Ghaffar Khan
 
Exponential and Logarthmic funtions (1)
Exponential and Logarthmic funtions (1)Exponential and Logarthmic funtions (1)
Exponential and Logarthmic funtions (1)
Ghaffar Khan
 
Functions
FunctionsFunctions
Functions
Ghaffar Khan
 
Quadratic And Polinomial Function
Quadratic And Polinomial FunctionQuadratic And Polinomial Function
Quadratic And Polinomial Function
Ghaffar Khan
 
Quadratic And Polinomial Function
 Quadratic And Polinomial Function Quadratic And Polinomial Function
Quadratic And Polinomial Function
Ghaffar Khan
 
Exponentioal And Logarthmic Functions
 Exponentioal And Logarthmic Functions Exponentioal And Logarthmic Functions
Exponentioal And Logarthmic Functions
Ghaffar Khan
 
Internet Protocol
Internet ProtocolInternet Protocol
Internet Protocol
Ghaffar Khan
 
Introduction to Computer Networks
 Introduction to Computer Networks Introduction to Computer Networks
Introduction to Computer Networks
Ghaffar Khan
 
Network Layer
Network LayerNetwork Layer
Network Layer
Ghaffar Khan
 
Control Structures
Control StructuresControl Structures
Control Structures
Ghaffar Khan
 
Input And Output
 Input And Output Input And Output
Input And Output
Ghaffar Khan
 
Surfaces
SurfacesSurfaces
Surfaces
Ghaffar Khan
 
Vector Tools
Vector ToolsVector Tools
Vector Tools
Ghaffar Khan
 
Drawing Tools
Drawing ToolsDrawing Tools
Drawing Tools
Ghaffar Khan
 
Drawing Figures
Drawing FiguresDrawing Figures
Drawing Figures
Ghaffar Khan
 
Computer Graphics Introduction
Computer Graphics IntroductionComputer Graphics Introduction
Computer Graphics Introduction
Ghaffar Khan
 
World is beautiful ... ...
World is beautiful ... ...World is beautiful ... ...
World is beautiful ... ...
Ghaffar Khan
 
My Presentation On Ajax
My Presentation On AjaxMy Presentation On Ajax
My Presentation On Ajax
Ghaffar Khan
 
How A Computer Works
How A Computer WorksHow A Computer Works
How A Computer Works
Ghaffar Khan
 
Exponential and Logarthmic funtions
Exponential and Logarthmic funtionsExponential and Logarthmic funtions
Exponential and Logarthmic funtions
Ghaffar Khan
 
Exponential and Logarthmic funtions (1)
Exponential and Logarthmic funtions (1)Exponential and Logarthmic funtions (1)
Exponential and Logarthmic funtions (1)
Ghaffar Khan
 
Quadratic And Polinomial Function
Quadratic And Polinomial FunctionQuadratic And Polinomial Function
Quadratic And Polinomial Function
Ghaffar Khan
 
Quadratic And Polinomial Function
 Quadratic And Polinomial Function Quadratic And Polinomial Function
Quadratic And Polinomial Function
Ghaffar Khan
 
Exponentioal And Logarthmic Functions
 Exponentioal And Logarthmic Functions Exponentioal And Logarthmic Functions
Exponentioal And Logarthmic Functions
Ghaffar Khan
 
Introduction to Computer Networks
 Introduction to Computer Networks Introduction to Computer Networks
Introduction to Computer Networks
Ghaffar Khan
 
Control Structures
Control StructuresControl Structures
Control Structures
Ghaffar Khan
 
Computer Graphics Introduction
Computer Graphics IntroductionComputer Graphics Introduction
Computer Graphics Introduction
Ghaffar Khan
 
Ad

Recently uploaded (20)

STKI Israel Market Study 2025 final v1 version
STKI Israel Market Study 2025 final v1 versionSTKI Israel Market Study 2025 final v1 version
STKI Israel Market Study 2025 final v1 version
Dr. Jimmy Schwarzkopf
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
Microsoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentationMicrosoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentation
Digitalmara
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
 
Dev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API WorkflowsDev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API Workflows
UiPathCommunity
 
Create Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent BuilderCreate Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent Builder
DianaGray10
 
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Peter Bittner
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
SDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhereSDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhere
Adtran
 
European Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility TestingEuropean Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility Testing
Julia Undeutsch
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
Droidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing HealthcareDroidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing Healthcare
Droidal LLC
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
STKI Israel Market Study 2025 final v1 version
STKI Israel Market Study 2025 final v1 versionSTKI Israel Market Study 2025 final v1 version
STKI Israel Market Study 2025 final v1 version
Dr. Jimmy Schwarzkopf
 
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 ADr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr Jimmy Schwarzkopf presentation on the SUMMIT 2025 A
Dr. Jimmy Schwarzkopf
 
Introducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and ARIntroducing FME Realize: A New Era of Spatial Computing and AR
Introducing FME Realize: A New Era of Spatial Computing and AR
Safe Software
 
Microsoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentationMicrosoft Build 2025 takeaways in one presentation
Microsoft Build 2025 takeaways in one presentation
Digitalmara
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...Cyber security cyber security cyber security cyber security cyber security cy...
Cyber security cyber security cyber security cyber security cyber security cy...
pranavbodhak
 
Dev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API WorkflowsDev Dives: System-to-system integration with UiPath API Workflows
Dev Dives: System-to-system integration with UiPath API Workflows
UiPathCommunity
 
Create Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent BuilderCreate Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent Builder
DianaGray10
 
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Nix(OS) for Python Developers - PyCon 25 (Bologna, Italia)
Peter Bittner
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk TechniciansOffshore IT Support: Balancing In-House and Offshore Help Desk Technicians
Offshore IT Support: Balancing In-House and Offshore Help Desk Technicians
john823664
 
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Protecting Your Sensitive Data with Microsoft Purview - IRMS 2025
Nikki Chapple
 
SDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhereSDG 9000 Series: Unleashing multigigabit everywhere
SDG 9000 Series: Unleashing multigigabit everywhere
Adtran
 
European Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility TestingEuropean Accessibility Act & Integrated Accessibility Testing
European Accessibility Act & Integrated Accessibility Testing
Julia Undeutsch
 
AI Trends - Mary Meeker
AI Trends - Mary MeekerAI Trends - Mary Meeker
AI Trends - Mary Meeker
Razin Mustafiz
 
Gihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai TechnologyGihbli AI and Geo sitution |use/misuse of Ai Technology
Gihbli AI and Geo sitution |use/misuse of Ai Technology
zainkhurram1111
 
Maxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing placeMaxx nft market place new generation nft marketing place
Maxx nft market place new generation nft marketing place
usersalmanrazdelhi
 
Droidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing HealthcareDroidal: AI Agents Revolutionizing Healthcare
Droidal: AI Agents Revolutionizing Healthcare
Droidal LLC
 
TrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy ContractingTrustArc Webinar: Mastering Privacy Contracting
TrustArc Webinar: Mastering Privacy Contracting
TrustArc
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 

For Loop

  • 1. The wizards of For Loop A Lecture By Abdul Ghaffar Khan
  • 2. ‘ C’ and Iterative Logic To apply the Iterative logic we have three control structures in ‘C’ Language as listed below, for Loop while loop do while loop Ch – 8 For Loop By Abdul Ghaffar Khan
  • 3. The for Loop: for loop is used when a process is to repeat a fixed number of times. The structure of a for loop is as follows for(expression_l; expression_2; expression_3) any_instruction; Or for(expression_l; expression_2; expression_3) { body-of-IOOP } Ch – 8 For Loop By Abdul Ghaffar Khan
  • 4. Order of execution When the loop is started normally a control variable is initialized by executing expression_l. expression_2 is tested if it is false then control is transferred outside the loop otherwise do next step 3 Body of loop is executed. Value of control variable is altered by expression_3 Steps (2) to (4) are repeated until condition becomes false Ch – 8 For Loop By Abdul Ghaffar Khan for(exl; ex2; ex3) { body-of-IOOP }
  • 5. Example 8.1 ( Print 10 natural numbers) Ch – 8 For Loop By Abdul Ghaffar Khan main() { int NBR; clrscr(); for(NBR=l; NBR<=10; ++NBR) printf(&quot;%d &quot;,NBR); getch() } Output: 2 3 4 5 6 7 8 9 10
  • 6. Example 8.2 ( print a table ) main() { int n, p, i= 0; clrscr(); printf(&quot;Enter a number whose table is to print &quot;); scanf(&quot;%d&quot;, &n); printf(&quot;Table of %d \n&quot;, n); for (i=1; i<=12; ++i) { p = i* n; printf(&quot;%d * %4 = %d\n&quot; n, i, p ); . } getch(); } Ch – 8 For Loop By Abdul Ghaffar Khan Output Enter a number whose table is to print 6 6 * 1 = 6 6 * 2 = 12 6 * 3 =18 6 * 4 = 24 6 * 5 = 30 6 * 6 = 36 6 * 7 = 42 6 * 8 = 48 6 * 9 = 54 6 * 10 = 60 6 * 11 = 66 6 * 12 = 72
  • 7. Example 8.3 Write down a program to generate the following output Ch – 8 For Loop By Abdul Ghaffar Khan C8 lower left corner BC lower right corner
  • 8. Example 8.3 void main(void) { int x, y; clrscr(); . printf (&quot;\xc9&quot;); for (x=1; x<72 ; ++x) { printf(&quot;\xcd&quot;) ; } printf(&quot;\xBB\n&quot;); // drawing vertical lines for (x=1;x<10;++x) { if (x==5) printf(&quot;\xBA\t\t\tWelcome To Learning C\t\t\t\t\xBA\n&quot;); printf(&quot;\xBA\t\t\t\t\t\t\t\t\t\xBA\n&quot;); } Ch – 8 For Loop By Abdul Ghaffar Khan printf(&quot;\xC8&quot;); // drawing bottom line for (x=1;x<72;++x) { printf(&quot;\xcd&quot;); } printf(&quot;\xBC\n&quot;) ; getch(); }
  • 9. Multiple assignments in the for loop We can use more than one initialization statement and more than one Increment decrement statements however only one condition is allowed within a for loop. When used multiple assignments or increment commas separate each statement. for( assignment I, asslgnment2; Condition; Increment1, intement2) . { body of loop } Ch – 8 For Loop By Abdul Ghaffar Khan
  • 10. Example 8.3 #include<stdio.h> #include<conio.h> void main(void) { int x, y; clrscr(); for(x = 1, y= 10; x<= 10; ++x, --y) printf(&quot;x = %d\tY = %d\n&quot;,x,y); getch(); ; } Ch – 8 For Loop By Abdul Ghaffar Khan Output: X= 1 Y = 10 X= 2 Y = 9 X= 3 Y = 8 X= 4 Y = 7 X=5 Y = 6 X=6 Y = 5 X=7 Y = 4 X=8 Y =3 X=9 Y =2 X=10 Y =1
  • 11. The break statement break statement is used to take immediate exit from the for loop. When break statement is executed the control immediately be transferred to the first statement following the for loop. Ch – 8 For Loop By Abdul Ghaffar Khan main() { for( exp_l ; exp_2; exp_3) { statement1; statement2; if( condition) beak; statement3; statement4; } statement5; statement6; }
  • 12. The continue statement Continue statement is used to skip the remaining statement in a loop this statement immediately transfer the control to the increment or decrement expression in the loop Ch – 8 For Loop By Abdul Ghaffar Khan main() { for( exp_l ; exp_2;exp_3) { statement 1; statement 2.; if( condition) continue; statement3; statement4; } statement5;. statement6; }
  • 13. Nested for loop: When a for loop is completely embedded ( enclosed) within another for loop, the structure is called nested for loop, Ch – 8 For Loop By Abdul Ghaffar Khan for ( exp1 ; condition;exp2) { body-of-loop 1 for( exp3; condition2;exp4) { body-of-loop2 } }
  • 14. Example 8.4 ( Factorials) void main(void) { int i,j; long fact; . clrscr(); for (i =1;i<=7;++i) { fact=l. for (j=i; j> I; --j) { fact *= j; } printf(&quot;\n%d! = %d\n&quot;,i,fact); } getch(); } Ch – 8 For Loop By Abdul Ghaffar Khan Output: 1! = I 2! =2 3! =6 4! =24 5! = 120 6! = 720 7! = 5040
  • 15. Example 8.5 ( Stars) void main(void) { int I,j; clrscr(); for (i =1;i<=10;++i) { for 0= 1; j<=i ; ++j) { printf('*'); , } printf(&quot;\n&quot;); } getch(); } Ch – 8 For Loop By Abdul Ghaffar Khan Output: * ** *** **** ***** ****** ******* ******** ********* **********