SlideShare a Scribd company logo
1 of 25
INSTRUCTOR:
ENGR. AFSHAN ASIM
CHAPTER # 3
LOOPS & DECISIONS
OBJECTIVES
• Relational operators.
• For Loop
• While Loop
• do while Loop
• Nested Loop
RELATIONAL OPERATORS
Operator Meaning
> Greater than
< Less than
== Equal to
!= Not equal to
>= Greater than or equal to
<= Less than or equal to
RELATIONAL OPERATORS (CONTD…)
int a=12; //assignment statement
int b=34; //assignment statement
(b<34) //false or 0
(b<=34) //true or 1
(a==12) //true or 1
(b!=35) //true or 1
(a>14) //false or 0
(a>=10) //true or 1
LOOPS
• Three kinds of loops
• For
• While
• Do-while
FOR LOOP
Syntax
•Single Statement Loop
for(variable initialization, condition, variable update)
statement; //executed if condition true
•Multi Statement Loop
for(variable initialization, condition, variable update)
{ //executed if condition true
statement1;
statement2;
}
FOR LOOP FLOW CHART
Initialization
Expression
Body of Loop
Increment
Expression
Test
Expression
Exit
false
True
FOR LOOP EXAMPLE
//single statement loop
#include<iostream>
using namespace std;
void main()
{
int i;
for(i=0;i<10;i++)
cout<<i<<endl;
system(“pause”);
}
FOR LOOP EXAMPLE
//multi statement loop
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int i;
for(i=0;i<10;i+=2)
{ //loop body starts
cout<<setw(4)<<i;
int j=i*i*i;
cout<<setw(6)<<j<<endl;
} //loop body ends
system(“pause”);
}
BLOCK & VARIABLE VISIBILITY
//multi statement loop
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int i;
for(i=0;i<10;i++)
{ //loop body starts
cout<<setw(4)<<I;
int j=i*i*i;
cout<<setw(6)<<j<<endl;
} //loop body ends
cout<<j; //ERROR
system(“pause”);
}
FOR LOOP VARIATIONS
//increment expression variations
#include<iostream>
using namespace std;
int main()
{
int i;
for(i=10;i>0;i--)
{ //loop body starts
cout<<i;
cout<<endl;
} //loop body ends
system(“pause”);
}
FOR LOOP VARIATIONS
//variables defined in for statement
#include<iostream>
using namespace std;
int main()
{
for(int i=0;i<10;i++)
{ //loop body starts
cout<<i;
cout<<endl;
} //loop body ends
system(“pause”);
}
FOR LOOP VARIATIONS
//multiple initialization and increment
expressions
#include<iostream>
using namespace std;
int main()
{
int i;
for(i=0,alpha=100;i<10;i++,alpha--)
{ //loop body starts
……..
cout<<i;
cout<<endl;
} //loop body ends
system(“pause”);
}
TASK
What happens if you use for loop in the
following manner
•for(;;)
•for(;;);
(Submit your answers in the next class)
WHILE LOOP
Syntax
•Single Statement while Loop
while(test expression)
statement;
•Multi Statement while Loop
while(test expression)
{
Body of loop
}
WHILE LOOP FLOW CHART
Body of Loop
Test
Expression
Exit
false
True
WHILE LOOP EXAMPLE
#include<iostream>
using namespace std;
int main()
{
int i=0;
while(i<10)
{
cout<<i<<endl;
i++;
}
system(“pause”);
}
DO WHILE LOOP
Syntax
do
{
Body of loop
}
while(test expression);
DO WHILE LOOP FLOW CHART
Body of Loop
Test
Expression
Exit
false
True
DO WHILE LOOP EXAMPLE
#include<iostream>
using namespace std;
int main()
{
int i=0;
do
{
cout<<i<<endl;
i++;
} while(i<10);
system(“pause”);
}
NESTED LOOPS
• Loops inside another loop
• Example
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<“Loop2”;
}
cout<<“nLoop1 “;
}
Inner Outer
NESTED LOOPS EXAMPLE
• Program to print the following
pattern
*
* *
* * *
* * * *
CONTD…
#include<iostream>
using namespace std;
int main()
{
int num=1;
for(int i=0;i<4;i++)
{
for(int j=0;j<num;j++)
{
cout<<“*”;
}
num++;
cout<<endl;
}
system(“pause”);
}
c++ Lecture 3

More Related Content

What's hot

One definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим житьOne definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим житьPlatonov Sergey
 
Planet of the AOPs
Planet of the AOPsPlanet of the AOPs
Planet of the AOPsJames Ward
 
Let's meet your expectations!
Let's meet your expectations!Let's meet your expectations!
Let's meet your expectations!Bartosz Polaczyk
 
3.looping(iteration statements)
3.looping(iteration statements)3.looping(iteration statements)
3.looping(iteration statements)Hardik gupta
 
Udp scriptstart
Udp scriptstartUdp scriptstart
Udp scriptstartdina_retiz
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loopsbsdeol28
 
Nested loop in C language
Nested loop in C languageNested loop in C language
Nested loop in C languageErumShammim
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetJose Perez
 
Perl 5.16 new features
Perl 5.16 new featuresPerl 5.16 new features
Perl 5.16 new featuresPavel Vlasov
 
Operating Systems - A Primer
Operating Systems - A PrimerOperating Systems - A Primer
Operating Systems - A PrimerSaumil Shah
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and loopingaprilyyy
 

What's hot (20)

One definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим житьOne definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим жить
 
Planet of the AOPs
Planet of the AOPsPlanet of the AOPs
Planet of the AOPs
 
Shell Script Tutorial
Shell Script TutorialShell Script Tutorial
Shell Script Tutorial
 
Rcpp11
Rcpp11Rcpp11
Rcpp11
 
Cs1123 6 loops
Cs1123 6 loopsCs1123 6 loops
Cs1123 6 loops
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Let's meet your expectations!
Let's meet your expectations!Let's meet your expectations!
Let's meet your expectations!
 
3.looping(iteration statements)
3.looping(iteration statements)3.looping(iteration statements)
3.looping(iteration statements)
 
Udp scriptstart
Udp scriptstartUdp scriptstart
Udp scriptstart
 
Advance ROP Attacks
Advance ROP AttacksAdvance ROP Attacks
Advance ROP Attacks
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
 
Nested loop in C language
Nested loop in C languageNested loop in C language
Nested loop in C language
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
 
Loops in JavaScript
Loops in JavaScriptLoops in JavaScript
Loops in JavaScript
 
Loop control in c++
Loop control in c++Loop control in c++
Loop control in c++
 
Perl 5.16 new features
Perl 5.16 new featuresPerl 5.16 new features
Perl 5.16 new features
 
Operating Systems - A Primer
Operating Systems - A PrimerOperating Systems - A Primer
Operating Systems - A Primer
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 

Similar to c++ Lecture 3

FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2rohassanie
 
Arduino section programming slides
Arduino section programming slidesArduino section programming slides
Arduino section programming slidesvivek k
 
Arduino Section Programming - from Sparkfun
Arduino Section Programming - from SparkfunArduino Section Programming - from Sparkfun
Arduino Section Programming - from SparkfunJhaeZaSangcapGarrido
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and loopingChaAstillas
 
Computer programming
Computer programmingComputer programming
Computer programmingXhyna Delfin
 
12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptxAqeelAbbas94
 
Arduino sectionprogramming slides
Arduino sectionprogramming slidesArduino sectionprogramming slides
Arduino sectionprogramming slidesJorge Joens
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statementsVladislav Hadzhiyski
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)SURBHI SAROHA
 
Elements of C++11
Elements of C++11Elements of C++11
Elements of C++11Uilian Ries
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)jewelyngrace
 
Cs1123 4 variables_constants
Cs1123 4 variables_constantsCs1123 4 variables_constants
Cs1123 4 variables_constantsTAlha MAlik
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structuresayshasafdarwaada
 

Similar to c++ Lecture 3 (20)

MUST CS101 Lab11
MUST CS101 Lab11 MUST CS101 Lab11
MUST CS101 Lab11
 
Loops c++
Loops c++Loops c++
Loops c++
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
Arduino section programming slides
Arduino section programming slidesArduino section programming slides
Arduino section programming slides
 
4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf
 
Arduino Section Programming - from Sparkfun
Arduino Section Programming - from SparkfunArduino Section Programming - from Sparkfun
Arduino Section Programming - from Sparkfun
 
Loops
LoopsLoops
Loops
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Computer programming
Computer programmingComputer programming
Computer programming
 
12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx12-Lec - Repetition For Loop.pptx
12-Lec - Repetition For Loop.pptx
 
Arduino sectionprogramming slides
Arduino sectionprogramming slidesArduino sectionprogramming slides
Arduino sectionprogramming slides
 
Operators loops conditional and statements
Operators loops conditional and statementsOperators loops conditional and statements
Operators loops conditional and statements
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)
 
Elements of C++11
Elements of C++11Elements of C++11
Elements of C++11
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
 
Loops In C++
Loops In C++Loops In C++
Loops In C++
 
3 rd animation
3 rd animation3 rd animation
3 rd animation
 
PLSQL (1).ppt
PLSQL (1).pptPLSQL (1).ppt
PLSQL (1).ppt
 
Cs1123 4 variables_constants
Cs1123 4 variables_constantsCs1123 4 variables_constants
Cs1123 4 variables_constants
 
Programming Fundamentals in C++ structures
Programming Fundamentals in  C++ structuresProgramming Fundamentals in  C++ structures
Programming Fundamentals in C++ structures
 

More from sajidpk92

Cauchy riemann equations
Cauchy riemann equationsCauchy riemann equations
Cauchy riemann equationssajidpk92
 
STEP(Solar Technology for Energy Production)
STEP(Solar Technology for Energy Production)STEP(Solar Technology for Energy Production)
STEP(Solar Technology for Energy Production)sajidpk92
 
c++ Lecture 4
c++ Lecture 4c++ Lecture 4
c++ Lecture 4sajidpk92
 
c++ Lecture 2
c++ Lecture 2c++ Lecture 2
c++ Lecture 2sajidpk92
 
c++ Lecture 1
c++ Lecture 1c++ Lecture 1
c++ Lecture 1sajidpk92
 
basic c++(1)
basic c++(1)basic c++(1)
basic c++(1)sajidpk92
 

More from sajidpk92 (8)

Cauchy riemann equations
Cauchy riemann equationsCauchy riemann equations
Cauchy riemann equations
 
STEP(Solar Technology for Energy Production)
STEP(Solar Technology for Energy Production)STEP(Solar Technology for Energy Production)
STEP(Solar Technology for Energy Production)
 
c++ Lecture 4
c++ Lecture 4c++ Lecture 4
c++ Lecture 4
 
c++ Lecture 2
c++ Lecture 2c++ Lecture 2
c++ Lecture 2
 
c++ Lecture 1
c++ Lecture 1c++ Lecture 1
c++ Lecture 1
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
basic c++(1)
basic c++(1)basic c++(1)
basic c++(1)
 

Recently uploaded

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 

Recently uploaded (20)

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 

c++ Lecture 3

  • 1.
  • 3. OBJECTIVES • Relational operators. • For Loop • While Loop • do while Loop • Nested Loop
  • 4. RELATIONAL OPERATORS Operator Meaning > Greater than < Less than == Equal to != Not equal to >= Greater than or equal to <= Less than or equal to
  • 5. RELATIONAL OPERATORS (CONTD…) int a=12; //assignment statement int b=34; //assignment statement (b<34) //false or 0 (b<=34) //true or 1 (a==12) //true or 1 (b!=35) //true or 1 (a>14) //false or 0 (a>=10) //true or 1
  • 6. LOOPS • Three kinds of loops • For • While • Do-while
  • 7. FOR LOOP Syntax •Single Statement Loop for(variable initialization, condition, variable update) statement; //executed if condition true •Multi Statement Loop for(variable initialization, condition, variable update) { //executed if condition true statement1; statement2; }
  • 8. FOR LOOP FLOW CHART Initialization Expression Body of Loop Increment Expression Test Expression Exit false True
  • 9. FOR LOOP EXAMPLE //single statement loop #include<iostream> using namespace std; void main() { int i; for(i=0;i<10;i++) cout<<i<<endl; system(“pause”); }
  • 10. FOR LOOP EXAMPLE //multi statement loop #include<iostream> #include<iomanip> using namespace std; int main() { int i; for(i=0;i<10;i+=2) { //loop body starts cout<<setw(4)<<i; int j=i*i*i; cout<<setw(6)<<j<<endl; } //loop body ends system(“pause”); }
  • 11. BLOCK & VARIABLE VISIBILITY //multi statement loop #include<iostream> #include<iomanip> using namespace std; int main() { int i; for(i=0;i<10;i++) { //loop body starts cout<<setw(4)<<I; int j=i*i*i; cout<<setw(6)<<j<<endl; } //loop body ends cout<<j; //ERROR system(“pause”); }
  • 12. FOR LOOP VARIATIONS //increment expression variations #include<iostream> using namespace std; int main() { int i; for(i=10;i>0;i--) { //loop body starts cout<<i; cout<<endl; } //loop body ends system(“pause”); }
  • 13. FOR LOOP VARIATIONS //variables defined in for statement #include<iostream> using namespace std; int main() { for(int i=0;i<10;i++) { //loop body starts cout<<i; cout<<endl; } //loop body ends system(“pause”); }
  • 14. FOR LOOP VARIATIONS //multiple initialization and increment expressions #include<iostream> using namespace std; int main() { int i; for(i=0,alpha=100;i<10;i++,alpha--) { //loop body starts …….. cout<<i; cout<<endl; } //loop body ends system(“pause”); }
  • 15. TASK What happens if you use for loop in the following manner •for(;;) •for(;;); (Submit your answers in the next class)
  • 16. WHILE LOOP Syntax •Single Statement while Loop while(test expression) statement; •Multi Statement while Loop while(test expression) { Body of loop }
  • 17. WHILE LOOP FLOW CHART Body of Loop Test Expression Exit false True
  • 18. WHILE LOOP EXAMPLE #include<iostream> using namespace std; int main() { int i=0; while(i<10) { cout<<i<<endl; i++; } system(“pause”); }
  • 19. DO WHILE LOOP Syntax do { Body of loop } while(test expression);
  • 20. DO WHILE LOOP FLOW CHART Body of Loop Test Expression Exit false True
  • 21. DO WHILE LOOP EXAMPLE #include<iostream> using namespace std; int main() { int i=0; do { cout<<i<<endl; i++; } while(i<10); system(“pause”); }
  • 22. NESTED LOOPS • Loops inside another loop • Example for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { cout<<“Loop2”; } cout<<“nLoop1 “; } Inner Outer
  • 23. NESTED LOOPS EXAMPLE • Program to print the following pattern * * * * * * * * * *
  • 24. CONTD… #include<iostream> using namespace std; int main() { int num=1; for(int i=0;i<4;i++) { for(int j=0;j<num;j++) { cout<<“*”; } num++; cout<<endl; } system(“pause”); }