SlideShare a Scribd company logo
Control Structure continued….
• Repetition structures
• C has three types:
• While
• do/while
• for
while
The while Repetition Structure
while
while (condition) action;
• Example in C:
int product=2;
while (product<=1000)
product=2*product;
product<=1000 product=2*product
Y
N
while
Counter-Controlled Repetition
#include <stdio.h>
void main() {
int counter, grade, total, average;
total=0;
counter=0;
while (counter < 10) {
printf("Enter grade:");
scanf("%d", &grade);
total+=grade;
counter++;
}
average=total/10;
printf("Class average is %dn", average);
}
(initialization)
(execute loop)
(termination)
Counter-Controlled Repetition
• Result
Enter grade:60
Enter grade:70
Enter grade:65
Enter grade:76
Enter grade:73
Enter grade:56
Enter grade:78
Enter grade:64
Enter grade:89
Enter grade:76
Class average is 70
Nested Control Structures
#include <stdio.h>
void main() {
int passed=0, failed=0, counter=0, result;
while (counter<10) {
printf("Enter result (1=pass, 2=fail):");
scanf("%d", &result);
if (result==1)
passed++;
else
failed++;
counter++;
}
Nested Control Structures
printf("Passed %dn", passed);
printf("Failed %dn", failed);
if (passed>8)
printf("Excellent Classn");
}
Enter result (1=pass, 2=fail):1
Enter result (1=pass, 2=fail):1
Enter result (1=pass, 2=fail):1
Enter result (1=pass, 2=fail):2
Enter result (1=pass, 2=fail):1
Enter result (1=pass, 2=fail):1
Enter result (1=pass, 2=fail):1
Enter result (1=pass, 2=fail):1
Enter result (1=pass, 2=fail):1
Enter result (1=pass, 2=fail):1
Passed 9
Failed 1
Excellent Class
do-while The do-while Repetition Structure
do while
do
action;
while (condition);
condition
action
Y
N
do-while The do-while Repetition Structure
• 1+2+…+100
#include <stdio.h>
void main() {
int s, i;
s=0;
i=1;
do {
s = s + i;
i++;
} while (i<=100);
printf("1+2+...+100=%dn", s);
}
The for Repetition Structure
for
for (expression1; expression2; expression3)
action;
expression2 action
Y
N
expression3
expression1
The for Repetition Structure
for
#include <stdio.h>
void main() {
int counter;
for (counter = 1; counter <= 10; counter++)
printf("%d ", counter);
}
1 2 3 4 5 6 7 8 9 10
The break Statement
break
#include <stdio.h>
void main() {
int x;
for (x = 1; x <= 10; x++) {
if (x == 5)
break;
printf("%d ", x);
}
printf("nBroke out of loop at x == %dn", x);
}
1 2 3 4
Broke out of loop at x == 5
break
The break Statement
Example: break in switch and for structure
for (i=1;i<=3;i++)
{ switch(i)
{ case 1: printf(“*n”);
break;
case 2: printf(“**n”);
break;
case 3: printf(“***n”);
break;
}
} *
**
***
for (i=1;i<=3;i++)
{ if (i==1) {printf(“*n”);
break;}
if (i==2) {printf(“**n”);
break;}
if (i==3) {printf(“***n”);
break;}
}
*
The continue Statement
continue
#include <stdio.h>
void main() {
int x;
x = 1;
while (x <= 10) {
if (x == 5)
continue;
printf("%d ", x);
x++;
}
}
1 2 3 4
#include <stdio.h>
void main() {
int x;
for (x = 1; x <= 10; x++) {
if (x == 5)
continue;
printf("%d ", x);
}
}
1 2 3 4 6 7 8 9 10
The goto Statement
goto
#include <stdio.h>
void main() {
int s=0, i=1;
Loop:
s = s + i;
i++;
if (i<=100) goto Loop;
printf("1+2+...+100=%dn", s);
}
1+2+…+100=5050
Label

More Related Content

What's hot

C Programming Language Part 4
C Programming Language Part 4C Programming Language Part 4
C Programming Language Part 4
Rumman Ansari
 
Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.harman kaur
 
rtrtrNew text document
rtrtrNew text documentrtrtrNew text document
rtrtrNew text document
Harish Khodke
 
Implementing string
Implementing stringImplementing string
Implementing string
mohamed sikander
 
Python Conditionals and Functions
Python Conditionals and FunctionsPython Conditionals and Functions
Python Conditionals and Functions
Pooja B S
 
Container adapters
Container adaptersContainer adapters
Container adapters
mohamed sikander
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
mohamed sikander
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
mohamed sikander
 
C questions
C questionsC questions
C questions
mohamed sikander
 
Pegomock, a mocking framework for Go
Pegomock, a mocking framework for GoPegomock, a mocking framework for Go
Pegomock, a mocking framework for Go
Peter Goetz
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
領一 和泉田
 
Oopsprc1e
Oopsprc1eOopsprc1e
Oopsprc1e
Ankit Dubey
 
C program to implement linked list using array abstract data type
C program to implement linked list using array abstract data typeC program to implement linked list using array abstract data type
C program to implement linked list using array abstract data type
loyola ICAM college of engineering and technology
 

What's hot (17)

C Programming Language Part 4
C Programming Language Part 4C Programming Language Part 4
C Programming Language Part 4
 
week-17x
week-17xweek-17x
week-17x
 
Program to illustrate Switch, Goto and Exit statements.
Program to illustrate Switch, Goto and  Exit statements.Program to illustrate Switch, Goto and  Exit statements.
Program to illustrate Switch, Goto and Exit statements.
 
rtrtrNew text document
rtrtrNew text documentrtrtrNew text document
rtrtrNew text document
 
3 flow
3 flow3 flow
3 flow
 
Implementing string
Implementing stringImplementing string
Implementing string
 
Python Conditionals and Functions
Python Conditionals and FunctionsPython Conditionals and Functions
Python Conditionals and Functions
 
Container adapters
Container adaptersContainer adapters
Container adapters
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
 
C questions
C questionsC questions
C questions
 
Pegomock, a mocking framework for Go
Pegomock, a mocking framework for GoPegomock, a mocking framework for Go
Pegomock, a mocking framework for Go
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
Oopsprc1e
Oopsprc1eOopsprc1e
Oopsprc1e
 
New text document
New text documentNew text document
New text document
 
C program to implement linked list using array abstract data type
C program to implement linked list using array abstract data typeC program to implement linked list using array abstract data type
C program to implement linked list using array abstract data type
 

Similar to Session05 iteration structure

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
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
NishmaNJ
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
جامعة القدس المفتوحة
 
6_A1944859510_21789_2_2018_06. Branching Statements.ppt
6_A1944859510_21789_2_2018_06. Branching Statements.ppt6_A1944859510_21789_2_2018_06. Branching Statements.ppt
6_A1944859510_21789_2_2018_06. Branching Statements.ppt
RithwikRanjan
 
Looping
LoopingLooping
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
kapil078
 
C# Control Statements, For loop, Do While.ppt
C# Control Statements, For loop, Do While.pptC# Control Statements, For loop, Do While.ppt
C# Control Statements, For loop, Do While.ppt
Riannel Tecson
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
msharshitha03s
 
UNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptxUNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptx
Abhishekkumarsingh630054
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
Komal Kotak
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2rohassanie
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
MomenMostafa
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
Vikash Dhal
 
C language
C languageC language
C language
Priya698357
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
C lab programs
C lab programsC lab programs
C lab programs
Dr. Prashant Vats
 
Some stuff about C++ and development
Some stuff about C++ and developmentSome stuff about C++ and development
Some stuff about C++ and development
Jon Jagger
 

Similar to Session05 iteration structure (20)

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
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
 
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثةشرح مقرر البرمجة 2   لغة جافا - الوحدة الثالثة
شرح مقرر البرمجة 2 لغة جافا - الوحدة الثالثة
 
6_A1944859510_21789_2_2018_06. Branching Statements.ppt
6_A1944859510_21789_2_2018_06. Branching Statements.ppt6_A1944859510_21789_2_2018_06. Branching Statements.ppt
6_A1944859510_21789_2_2018_06. Branching Statements.ppt
 
Looping
LoopingLooping
Looping
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 
C# Control Statements, For loop, Do While.ppt
C# Control Statements, For loop, Do While.pptC# Control Statements, For loop, Do While.ppt
C# Control Statements, For loop, Do While.ppt
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
UNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptxUNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptx
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Unix Programs
Unix ProgramsUnix Programs
Unix Programs
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
5 c control statements looping
5  c control statements looping5  c control statements looping
5 c control statements looping
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
 
C language
C languageC language
C language
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Some stuff about C++ and development
Some stuff about C++ and developmentSome stuff about C++ and development
Some stuff about C++ and development
 

More from HarithaRanasinghe

Session11 single dimarrays
Session11 single dimarraysSession11 single dimarrays
Session11 single dimarrays
HarithaRanasinghe
 
Session09 multi dimarrays
Session09 multi dimarraysSession09 multi dimarrays
Session09 multi dimarrays
HarithaRanasinghe
 
Session04 selection structure_b
Session04 selection structure_bSession04 selection structure_b
Session04 selection structure_b
HarithaRanasinghe
 
Session04 selection structure_a
Session04 selection structure_aSession04 selection structure_a
Session04 selection structure_a
HarithaRanasinghe
 
Session01 basics programming
Session01 basics programmingSession01 basics programming
Session01 basics programming
HarithaRanasinghe
 
Sad sample paper - mcq answers
Sad   sample paper - mcq answersSad   sample paper - mcq answers
Sad sample paper - mcq answers
HarithaRanasinghe
 
Model paper algorithms and data structures
Model paper  algorithms and data structuresModel paper  algorithms and data structures
Model paper algorithms and data structures
HarithaRanasinghe
 

More from HarithaRanasinghe (20)

Session12 pointers
Session12 pointersSession12 pointers
Session12 pointers
 
Session11 single dimarrays
Session11 single dimarraysSession11 single dimarrays
Session11 single dimarrays
 
Session09 multi dimarrays
Session09 multi dimarraysSession09 multi dimarrays
Session09 multi dimarrays
 
Session07 recursion
Session07 recursionSession07 recursion
Session07 recursion
 
Session06 functions
Session06 functionsSession06 functions
Session06 functions
 
Session04 selection structure_b
Session04 selection structure_bSession04 selection structure_b
Session04 selection structure_b
 
Session04 selection structure_a
Session04 selection structure_aSession04 selection structure_a
Session04 selection structure_a
 
Session03 operators
Session03 operatorsSession03 operators
Session03 operators
 
Session02 c intro
Session02 c introSession02 c intro
Session02 c intro
 
Session01 basics programming
Session01 basics programmingSession01 basics programming
Session01 basics programming
 
Program flow charts
Program flow chartsProgram flow charts
Program flow charts
 
Sad -sample_paper
Sad  -sample_paperSad  -sample_paper
Sad -sample_paper
 
Sad sample paper - mcq answers
Sad   sample paper - mcq answersSad   sample paper - mcq answers
Sad sample paper - mcq answers
 
Paper
PaperPaper
Paper
 
Model questions
Model questionsModel questions
Model questions
 
Model paper algorithms and data structures
Model paper  algorithms and data structuresModel paper  algorithms and data structures
Model paper algorithms and data structures
 
Doc 20180208-wa0001
Doc 20180208-wa0001Doc 20180208-wa0001
Doc 20180208-wa0001
 
Doc 20180130-wa0006
Doc 20180130-wa0006Doc 20180130-wa0006
Doc 20180130-wa0006
 
Doc 20180130-wa0005
Doc 20180130-wa0005Doc 20180130-wa0005
Doc 20180130-wa0005
 
Doc 20180130-wa0004-1
Doc 20180130-wa0004-1Doc 20180130-wa0004-1
Doc 20180130-wa0004-1
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 

Session05 iteration structure

  • 1. Control Structure continued…. • Repetition structures • C has three types: • While • do/while • for
  • 2. while The while Repetition Structure while while (condition) action; • Example in C: int product=2; while (product<=1000) product=2*product; product<=1000 product=2*product Y N while
  • 3. Counter-Controlled Repetition #include <stdio.h> void main() { int counter, grade, total, average; total=0; counter=0; while (counter < 10) { printf("Enter grade:"); scanf("%d", &grade); total+=grade; counter++; } average=total/10; printf("Class average is %dn", average); } (initialization) (execute loop) (termination)
  • 4. Counter-Controlled Repetition • Result Enter grade:60 Enter grade:70 Enter grade:65 Enter grade:76 Enter grade:73 Enter grade:56 Enter grade:78 Enter grade:64 Enter grade:89 Enter grade:76 Class average is 70
  • 5. Nested Control Structures #include <stdio.h> void main() { int passed=0, failed=0, counter=0, result; while (counter<10) { printf("Enter result (1=pass, 2=fail):"); scanf("%d", &result); if (result==1) passed++; else failed++; counter++; }
  • 6. Nested Control Structures printf("Passed %dn", passed); printf("Failed %dn", failed); if (passed>8) printf("Excellent Classn"); } Enter result (1=pass, 2=fail):1 Enter result (1=pass, 2=fail):1 Enter result (1=pass, 2=fail):1 Enter result (1=pass, 2=fail):2 Enter result (1=pass, 2=fail):1 Enter result (1=pass, 2=fail):1 Enter result (1=pass, 2=fail):1 Enter result (1=pass, 2=fail):1 Enter result (1=pass, 2=fail):1 Enter result (1=pass, 2=fail):1 Passed 9 Failed 1 Excellent Class
  • 7. do-while The do-while Repetition Structure do while do action; while (condition); condition action Y N
  • 8. do-while The do-while Repetition Structure • 1+2+…+100 #include <stdio.h> void main() { int s, i; s=0; i=1; do { s = s + i; i++; } while (i<=100); printf("1+2+...+100=%dn", s); }
  • 9. The for Repetition Structure for for (expression1; expression2; expression3) action; expression2 action Y N expression3 expression1
  • 10. The for Repetition Structure for #include <stdio.h> void main() { int counter; for (counter = 1; counter <= 10; counter++) printf("%d ", counter); } 1 2 3 4 5 6 7 8 9 10
  • 11. The break Statement break #include <stdio.h> void main() { int x; for (x = 1; x <= 10; x++) { if (x == 5) break; printf("%d ", x); } printf("nBroke out of loop at x == %dn", x); } 1 2 3 4 Broke out of loop at x == 5
  • 12. break The break Statement Example: break in switch and for structure for (i=1;i<=3;i++) { switch(i) { case 1: printf(“*n”); break; case 2: printf(“**n”); break; case 3: printf(“***n”); break; } } * ** *** for (i=1;i<=3;i++) { if (i==1) {printf(“*n”); break;} if (i==2) {printf(“**n”); break;} if (i==3) {printf(“***n”); break;} } *
  • 13. The continue Statement continue #include <stdio.h> void main() { int x; x = 1; while (x <= 10) { if (x == 5) continue; printf("%d ", x); x++; } } 1 2 3 4 #include <stdio.h> void main() { int x; for (x = 1; x <= 10; x++) { if (x == 5) continue; printf("%d ", x); } } 1 2 3 4 6 7 8 9 10
  • 14. The goto Statement goto #include <stdio.h> void main() { int s=0, i=1; Loop: s = s + i; i++; if (i<=100) goto Loop; printf("1+2+...+100=%dn", s); } 1+2+…+100=5050 Label