SlideShare a Scribd company logo
1 of 30
Introduction ttoo PPrrooggrraammmmiinngg 
LLeeccttuurree NNoo.. 88
IInn tthhee llaasstt lleeccttuurree 
 LLooooppss 
– WWhhiillee 
– DDoo wwhhiillee 
– FFoorr 
 OOppeerraattoorrss 
– IInnccrreemmeenntt // DDeeccrreemmeenntt 
– CCoommppoouunndd AAssssiiggnnmmeenntt OOppeerraattoorrss
EExxaammppllee:: PPrrooggrraamm ttoo ccaallccuullaattee 
tthhee aavveerraaggee mmaarrkkss ooff ccllaassss 
iinntt ssuumm;; 
iinntt ssttuuddeennttss ;; 
iinntt aavveerraaggee ;; 
ssuumm == 00 ;; 
ssttuuddeennttss == 00 ;; 
ddoo 
{{ 
cciinn >>>> ggrraaddee ;; 
ssuumm ++== ggrraaddee ;; 
ssttuuddeennttss ++++ ;; 
}} 
wwhhiillee ((ggrraaddee >>== 00)) ;; 
aavveerraaggee == ssuumm // ssttuuddeennttss ;; 
ccoouutt <<<< aavveerraaggee ;; 
A Flaw in the code
MMuullttii--wwaayy 
ddeecciissiioonn
iiff SSttaatteemmeennttss 
if (( ggrraaddee ====‘‘AA’’ )) 
ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; 
iiff (( ggrraaddee ====‘‘BB’’ )) 
ccoouutt <<<< ““ VVeerryy GGoooodd ”” ;; 
iiff (( ggrraaddee ====‘‘CC’’ )) 
ccoouutt <<<< ““ GGoooodd ”” ;; 
iiff (( ggrraaddee ====‘‘DD’’ )) 
ccoouutt <<<< ““ PPoooorr ”” ;; 
iiff (( ggrraaddee ====‘‘FF’’ )) 
ccoouutt <<<< ““ FFaaiill ”” ;;
iiff eellssee 
if (( ggrraaddee ====‘‘AA’’ )) 
ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; 
eellssee 
iiff (( ggrraaddee ====‘‘BB’’ )) 
ccoouutt <<<< ““ VVeerryy GGoooodd ”” ;; 
eellssee 
iiff (( ggrraaddee ====‘‘CC’’ )) 
ccoouutt <<<< ““ GGoooodd ”” ;; 
eellssee 
iiff (( ggrraaddee ====‘‘DD’’ )) 
ccoouutt <<<< ““ PPoooorr ”” ;;
iiff eellssee 
if (( ggrraaddee ==== ‘‘AA’’ )) 
ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; 
eellssee iiff (( ggrraaddee ==== ‘‘BB’’ )) 
…… 
eellssee iiff …… 
…… 
eellssee ……
sswwiittcchh 
ssttaatteemmeenntt
sswwiittcchh ssttaatteemmeennttss 
sswwiittcchh (( vvaarriiaabbllee nnaammee )) 
{{ 
ccaassee ‘‘aa’’ :: 
ssttaatteemmeennttss;; 
ccaassee ‘‘bb’’ :: 
ssttaatteemmeennttss;; 
ccaassee ‘‘cc’’ :: 
ssttaatteemmeennttss;; 
…… 
}}
sswwiittcchh ssttaatteemmeennttss 
sswwiittcchh (( ggrraaddee)) 
{{ 
ccaassee ‘‘AA’’ :: 
ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; 
ccaassee ‘‘BB’’ :: 
ccoouutt <<<< ““ VVeerryy GGoooodd ”” ;; 
ccaassee ‘‘CC’’ :: 
…… 
…… 
}}
switch statements 
ccaassee ‘‘AA’’ :: 
ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; 
…… 
……
EExxaammppllee 
sswwiittcchh (( ggrraaddee)) 
{{ 
ccaassee ‘‘AA’’ :: 
ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; 
ccaassee ‘‘BB’’ :: 
ccoouutt <<<< ““ VVeerryy GGoooodd ”” ;; 
ccaassee ‘‘CC’’ :: 
ccoouutt <<<< ““GGoooodd ”” ;; 
ccaassee ‘‘DD’’ :: 
ccoouutt <<<< ““ PPoooorr ”” ;; 
ccaassee ‘‘FF’’ :: 
ccoouutt <<<< ““ FFaaiill ”” ;; 
}}
bbrreeaakk;;
EExxaammppllee 
sswwiittcchh (( ggrraaddee )) 
{{ 
ccaassee ‘‘AA’’ :: 
ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; 
bbrreeaakk ;; 
ccaassee ‘‘BB’’ :: 
ccoouutt <<<< ““ VVeerryy GGoooodd ”” ;; 
bbrreeaakk ;; 
ccaassee ‘‘CC’’ :: 
ccoouutt <<<< ““GGoooodd ”” ;; 
bbrreeaakk ;; 
ccaassee ‘‘DD’’ :: 
ccoouutt <<<< ““ PPoooorr ”” ;; 
bbrreeaakk ;; 
ccaassee ‘‘FF’’ :: 
ccoouutt <<<< ““ FFaaiill ”” ;; 
bbrreeaakk ;; 
}}
ddeeffaauulltt :: 
ddeeffaauulltt :: 
ccoouutt <<<< ““ PPlleeaassee EEnntteerr GGrraaddee 
ffrroomm ‘‘AA’’ ttoo ‘‘DD’’ oorr ‘‘FF’’ ““ ;;
Flow Chart ooff sswwiittcchh ssttaatteemmeenntt 
switch (grade) 
case ‘A’ : 
Display 
“Excellent” 
case ‘B’ : 
Display 
“Very Good” 
… 
Default : 
“……..”
if ( amount >> 22333355..0099 )) 
ssttaatteemmeennttss ;;
WWhhoollee NNuummbbeerr 
 sshhoorrtt 
 iinntt 
 lloonngg
ccaassee ‘‘AA’’ :: 
ccaassee ‘‘ 330000 ‘‘ :: 
ccaassee ‘‘ ff ‘‘ ::
bbrreeaakk ;; 
iiff ((cc ==== ‘‘zz’’ )) 
{{ 
ccoouutt <<<< ““ GGrreeaatt !! YYoouu hhaavvee mmaaddee tthhee ccoorrrreecctt gguueessss ““ ;; 
bbrreeaakk ;; 
}}
ccoonnttiinnuuee ;;
ccoonnttiinnuuee 
wwhhiillee ttrryynnuumm <<== 55 ;; 
{{ 
…….. 
…….. 
ccoonnttiinnuuee ;; 
}}
ccoonnttiinnuuee iinn ‘‘ffoorr’’ lloooopp 
for ( counter = 0 ;counter <= 100 ;; ccoouunntteerr ++++ )) 
{{ 
………….. 
ccoonnttiinnuuee ;; 
}}
WWhhaatt hhaavvee wwee ddoonnee ttiillll nnooww …… 
 SSeeqquueennttiiaall SSttaatteemmeennttss 
 DDeecciissiioonnss 
– iiff ,, iiff eellssee ,, sswwiittcchh 
 LLooooppss 
– wwhhiillee ,, ddoo wwhhiillee ,, ffoorr
ggoottoo 
UUnnccoonnddiittiioonnaall BBrraanncchh ooff EExxeeccuuttiioonn
SSttrruuccttuurreedd PPrrooggrraammmmiinngg 
 SSeeqquueenncceess 
 DDeecciissiioonnss 
 LLooooppss
 MMiinniimmiizzee tthhee uussee ooff bbrreeaakk 
 MMiinniimmiizzee tthhee uussee ooff ccoonnttiinnuuee 
 NNeevveerr uussee ggoottoo
GGuuiiddee lliinneess ffoorr 
ssttrruuccttuurreedd pprrooggrraammmmiinngg 
 MMoodduullaarr 
 SSiinnggllee eennttrryy -- ssiinnggllee eexxiitt
RRuulleess ffoorr SSttrruuccttuurreedd 
Rule 1 : Use the ssiimmpplleesstt fflloowwcchhaarrtt 
RRuullee 22 :: AAnnyy rreeccttaannggllee ccaann bbee rreeppllaacceedd bbyy 
ttwwoo rreeccttaanngglleess.. 
RRuullee 33 :: AAnnyy rreeccttaannggllee ccaann bbee rreeppllaacceedd 
wwiitthh 
ssttrruuccttuurreedd fflloowwcchhaarrttiinngg 
ccoonnssttrruuccttss.. 
RRuullee 44 :: IItt ssaayyss,, rruullee 22 aanndd rruullee 33 ccaann bbee 
rreeppeeaatteedd aass mmaannyy ttiimmeess aass 
nneeeeddeedd 
FFlloowwcchhaarrtt
NNeexxtt MMiilleessttoonneess 
 DDaattaa SSttrruuccttuurreess 
– AArrrraayyss 
 CChhaarraacctteerr 
SSttrriinnggss 
 PPooiinntteerrss

More Related Content

What's hot

CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 16CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 16Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03Bilal Ahmed
 
निर्माण खंड 1 के एटलस. hindi हिन्दी
निर्माण खंड 1 के एटलस. hindi हिन्दीनिर्माण खंड 1 के एटलस. hindi हिन्दी
निर्माण खंड 1 के एटलस. hindi हिन्दीHarunyahyaHindi
 
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 15
CS201- Introduction to Programming- Lecture 15CS201- Introduction to Programming- Lecture 15
CS201- Introduction to Programming- Lecture 15Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41Bilal Ahmed
 
[TGDF 2014] 進階Shader技術
[TGDF 2014] 進階Shader技術[TGDF 2014] 進階Shader技術
[TGDF 2014] 進階Shader技術Owen Wu
 
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33Bilal Ahmed
 
Grade 12 U0-L4-GraphicalMethods
Grade 12 U0-L4-GraphicalMethodsGrade 12 U0-L4-GraphicalMethods
Grade 12 U0-L4-GraphicalMethodsgruszecki1
 
Edit data base menggunakan web
Edit data base menggunakan webEdit data base menggunakan web
Edit data base menggunakan webhaviedz miftah
 
CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36Bilal Ahmed
 
Grade 12 U0-L3-ErrorEstimation
Grade 12 U0-L3-ErrorEstimationGrade 12 U0-L3-ErrorEstimation
Grade 12 U0-L3-ErrorEstimationgruszecki1
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22Bilal Ahmed
 
Contrats speciaux du commerce maritime
  Contrats speciaux du commerce maritime  Contrats speciaux du commerce maritime
Contrats speciaux du commerce maritimeRabah HELAL
 
CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23Bilal Ahmed
 
Perangkat Keras Hardware
Perangkat Keras HardwarePerangkat Keras Hardware
Perangkat Keras HardwareJohan19931106
 

What's hot (20)

CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 16CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 16
 
CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 03
 
निर्माण खंड 1 के एटलस. hindi हिन्दी
निर्माण खंड 1 के एटलस. hindi हिन्दीनिर्माण खंड 1 के एटलस. hindi हिन्दी
निर्माण खंड 1 के एटलस. hindi हिन्दी
 
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 44
 
CS201- Introduction to Programming- Lecture 15
CS201- Introduction to Programming- Lecture 15CS201- Introduction to Programming- Lecture 15
CS201- Introduction to Programming- Lecture 15
 
CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41CS201- Introduction to Programming- Lecture 41
CS201- Introduction to Programming- Lecture 41
 
[TGDF 2014] 進階Shader技術
[TGDF 2014] 進階Shader技術[TGDF 2014] 進階Shader技術
[TGDF 2014] 進階Shader技術
 
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 38
 
CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 14
 
CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 26
 
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 33
 
Grade 12 U0-L4-GraphicalMethods
Grade 12 U0-L4-GraphicalMethodsGrade 12 U0-L4-GraphicalMethods
Grade 12 U0-L4-GraphicalMethods
 
Edit data base menggunakan web
Edit data base menggunakan webEdit data base menggunakan web
Edit data base menggunakan web
 
CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 36
 
Grade 12 U0-L3-ErrorEstimation
Grade 12 U0-L3-ErrorEstimationGrade 12 U0-L3-ErrorEstimation
Grade 12 U0-L3-ErrorEstimation
 
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 22
 
Contrats speciaux du commerce maritime
  Contrats speciaux du commerce maritime  Contrats speciaux du commerce maritime
Contrats speciaux du commerce maritime
 
CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23CS201- Introduction to Programming- Lecture 23
CS201- Introduction to Programming- Lecture 23
 
Hardware
HardwareHardware
Hardware
 
Perangkat Keras Hardware
Perangkat Keras HardwarePerangkat Keras Hardware
Perangkat Keras Hardware
 

Viewers also liked

CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 39
CS101- Introduction to Computing- Lecture 39CS101- Introduction to Computing- Lecture 39
CS101- Introduction to Computing- Lecture 39Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 30
MGT101 - Financial Accounting- Lecture 30MGT101 - Financial Accounting- Lecture 30
MGT101 - Financial Accounting- Lecture 30Bilal Ahmed
 
ENG101- English Comprehension- Lecture 43
ENG101- English Comprehension- Lecture 43ENG101- English Comprehension- Lecture 43
ENG101- English Comprehension- Lecture 43Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 37
CS101- Introduction to Computing- Lecture 37CS101- Introduction to Computing- Lecture 37
CS101- Introduction to Computing- Lecture 37Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10Bilal Ahmed
 
ENG101- English Comprehension- Lecture 45
ENG101- English Comprehension- Lecture 45ENG101- English Comprehension- Lecture 45
ENG101- English Comprehension- Lecture 45Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35Bilal Ahmed
 
ENG101- English Comprehension- Lecture 30
ENG101- English Comprehension- Lecture 30ENG101- English Comprehension- Lecture 30
ENG101- English Comprehension- Lecture 30Bilal Ahmed
 
ENG101- English Comprehension- Lecture 36
ENG101- English Comprehension- Lecture 36ENG101- English Comprehension- Lecture 36
ENG101- English Comprehension- Lecture 36Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 44
MGT101 - Financial Accounting- Lecture 44MGT101 - Financial Accounting- Lecture 44
MGT101 - Financial Accounting- Lecture 44Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 31
CS101- Introduction to Computing- Lecture 31CS101- Introduction to Computing- Lecture 31
CS101- Introduction to Computing- Lecture 31Bilal Ahmed
 
ENG101- English Comprehension- Lecture 23
ENG101- English Comprehension- Lecture 23ENG101- English Comprehension- Lecture 23
ENG101- English Comprehension- Lecture 23Bilal Ahmed
 
ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42Bilal Ahmed
 
MGT101 - Financial Accounting- Lecture 27
MGT101 - Financial Accounting- Lecture 27MGT101 - Financial Accounting- Lecture 27
MGT101 - Financial Accounting- Lecture 27Bilal Ahmed
 
ENG101- English Comprehension- Lecture 28
ENG101- English Comprehension- Lecture 28ENG101- English Comprehension- Lecture 28
ENG101- English Comprehension- Lecture 28Bilal Ahmed
 
ENG101- English Comprehension- Lecture 24
ENG101- English Comprehension- Lecture 24ENG101- English Comprehension- Lecture 24
ENG101- English Comprehension- Lecture 24Bilal Ahmed
 
ENG101- English Comprehension- Lecture 35
ENG101- English Comprehension- Lecture 35ENG101- English Comprehension- Lecture 35
ENG101- English Comprehension- Lecture 35Bilal Ahmed
 
CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38Bilal Ahmed
 

Viewers also liked (20)

CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 32
 
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29
 
CS101- Introduction to Computing- Lecture 39
CS101- Introduction to Computing- Lecture 39CS101- Introduction to Computing- Lecture 39
CS101- Introduction to Computing- Lecture 39
 
MGT101 - Financial Accounting- Lecture 30
MGT101 - Financial Accounting- Lecture 30MGT101 - Financial Accounting- Lecture 30
MGT101 - Financial Accounting- Lecture 30
 
ENG101- English Comprehension- Lecture 43
ENG101- English Comprehension- Lecture 43ENG101- English Comprehension- Lecture 43
ENG101- English Comprehension- Lecture 43
 
CS101- Introduction to Computing- Lecture 37
CS101- Introduction to Computing- Lecture 37CS101- Introduction to Computing- Lecture 37
CS101- Introduction to Computing- Lecture 37
 
CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10CS201- Introduction to Programming- Lecture 10
CS201- Introduction to Programming- Lecture 10
 
ENG101- English Comprehension- Lecture 45
ENG101- English Comprehension- Lecture 45ENG101- English Comprehension- Lecture 45
ENG101- English Comprehension- Lecture 45
 
CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35CS101- Introduction to Computing- Lecture 35
CS101- Introduction to Computing- Lecture 35
 
ENG101- English Comprehension- Lecture 30
ENG101- English Comprehension- Lecture 30ENG101- English Comprehension- Lecture 30
ENG101- English Comprehension- Lecture 30
 
ENG101- English Comprehension- Lecture 36
ENG101- English Comprehension- Lecture 36ENG101- English Comprehension- Lecture 36
ENG101- English Comprehension- Lecture 36
 
MGT101 - Financial Accounting- Lecture 44
MGT101 - Financial Accounting- Lecture 44MGT101 - Financial Accounting- Lecture 44
MGT101 - Financial Accounting- Lecture 44
 
CS101- Introduction to Computing- Lecture 31
CS101- Introduction to Computing- Lecture 31CS101- Introduction to Computing- Lecture 31
CS101- Introduction to Computing- Lecture 31
 
ENG101- English Comprehension- Lecture 23
ENG101- English Comprehension- Lecture 23ENG101- English Comprehension- Lecture 23
ENG101- English Comprehension- Lecture 23
 
ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42ENG101- English Comprehension- Lecture 42
ENG101- English Comprehension- Lecture 42
 
MGT101 - Financial Accounting- Lecture 27
MGT101 - Financial Accounting- Lecture 27MGT101 - Financial Accounting- Lecture 27
MGT101 - Financial Accounting- Lecture 27
 
ENG101- English Comprehension- Lecture 28
ENG101- English Comprehension- Lecture 28ENG101- English Comprehension- Lecture 28
ENG101- English Comprehension- Lecture 28
 
ENG101- English Comprehension- Lecture 24
ENG101- English Comprehension- Lecture 24ENG101- English Comprehension- Lecture 24
ENG101- English Comprehension- Lecture 24
 
ENG101- English Comprehension- Lecture 35
ENG101- English Comprehension- Lecture 35ENG101- English Comprehension- Lecture 35
ENG101- English Comprehension- Lecture 35
 
CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38
 

Similar to CS201- Introduction to Programming- Lecture 08

CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 11CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 11Bilal Ahmed
 
Design of the South Doña Ana Dam
Design of the South Doña Ana DamDesign of the South Doña Ana Dam
Design of the South Doña Ana DamDesh Sonyok
 
CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31Bilal Ahmed
 
21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii21 High-quality programming code construction part-ii
21 High-quality programming code construction part-iimaznabili
 
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 05
CS201- Introduction to Programming- Lecture 05CS201- Introduction to Programming- Lecture 05
CS201- Introduction to Programming- Lecture 05Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27Bilal Ahmed
 
Test Automation Myths
Test Automation MythsTest Automation Myths
Test Automation Mythskevinburr
 
WSB day 1 ecology
WSB day 1 ecologyWSB day 1 ecology
WSB day 1 ecologynlightowler
 
CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09Bilal Ahmed
 

Similar to CS201- Introduction to Programming- Lecture 08 (18)

CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35CS201- Introduction to Programming- Lecture 35
CS201- Introduction to Programming- Lecture 35
 
CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 11CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 11
 
Design of the South Doña Ana Dam
Design of the South Doña Ana DamDesign of the South Doña Ana Dam
Design of the South Doña Ana Dam
 
CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31CS201- Introduction to Programming- Lecture 31
CS201- Introduction to Programming- Lecture 31
 
21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii21 High-quality programming code construction part-ii
21 High-quality programming code construction part-ii
 
Physics report
Physics reportPhysics report
Physics report
 
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 37
 
CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45CS201- Introduction to Programming- Lecture 45
CS201- Introduction to Programming- Lecture 45
 
CS201- Introduction to Programming- Lecture 05
CS201- Introduction to Programming- Lecture 05CS201- Introduction to Programming- Lecture 05
CS201- Introduction to Programming- Lecture 05
 
CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 30
 
Regulation industrielle
Regulation industrielleRegulation industrielle
Regulation industrielle
 
CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 27
 
Test Automation Myths
Test Automation MythsTest Automation Myths
Test Automation Myths
 
ram new
ram newram new
ram new
 
WSB day 1 ecology
WSB day 1 ecologyWSB day 1 ecology
WSB day 1 ecology
 
Glaucoma
GlaucomaGlaucoma
Glaucoma
 
Tiro parabólico
Tiro parabólicoTiro parabólico
Tiro parabólico
 
CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09CS201- Introduction to Programming- Lecture 09
CS201- Introduction to Programming- Lecture 09
 

More from Bilal Ahmed

CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 29CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 29Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18Bilal Ahmed
 
CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17Bilal Ahmed
 

More from Bilal Ahmed (11)

CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43CS201- Introduction to Programming- Lecture 43
CS201- Introduction to Programming- Lecture 43
 
CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42CS201- Introduction to Programming- Lecture 42
CS201- Introduction to Programming- Lecture 42
 
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 39
 
CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32CS201- Introduction to Programming- Lecture 32
CS201- Introduction to Programming- Lecture 32
 
CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 29CS201- Introduction to Programming- Lecture 29
CS201- Introduction to Programming- Lecture 29
 
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 28
 
CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24CS201- Introduction to Programming- Lecture 24
CS201- Introduction to Programming- Lecture 24
 
CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 21
 
CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19CS201- Introduction to Programming- Lecture 19
CS201- Introduction to Programming- Lecture 19
 
CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18CS201- Introduction to Programming- Lecture 18
CS201- Introduction to Programming- Lecture 18
 
CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17CS201- Introduction to Programming- Lecture 17
CS201- Introduction to Programming- Lecture 17
 

CS201- Introduction to Programming- Lecture 08

  • 1. Introduction ttoo PPrrooggrraammmmiinngg LLeeccttuurree NNoo.. 88
  • 2. IInn tthhee llaasstt lleeccttuurree  LLooooppss – WWhhiillee – DDoo wwhhiillee – FFoorr  OOppeerraattoorrss – IInnccrreemmeenntt // DDeeccrreemmeenntt – CCoommppoouunndd AAssssiiggnnmmeenntt OOppeerraattoorrss
  • 3. EExxaammppllee:: PPrrooggrraamm ttoo ccaallccuullaattee tthhee aavveerraaggee mmaarrkkss ooff ccllaassss iinntt ssuumm;; iinntt ssttuuddeennttss ;; iinntt aavveerraaggee ;; ssuumm == 00 ;; ssttuuddeennttss == 00 ;; ddoo {{ cciinn >>>> ggrraaddee ;; ssuumm ++== ggrraaddee ;; ssttuuddeennttss ++++ ;; }} wwhhiillee ((ggrraaddee >>== 00)) ;; aavveerraaggee == ssuumm // ssttuuddeennttss ;; ccoouutt <<<< aavveerraaggee ;; A Flaw in the code
  • 5. iiff SSttaatteemmeennttss if (( ggrraaddee ====‘‘AA’’ )) ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; iiff (( ggrraaddee ====‘‘BB’’ )) ccoouutt <<<< ““ VVeerryy GGoooodd ”” ;; iiff (( ggrraaddee ====‘‘CC’’ )) ccoouutt <<<< ““ GGoooodd ”” ;; iiff (( ggrraaddee ====‘‘DD’’ )) ccoouutt <<<< ““ PPoooorr ”” ;; iiff (( ggrraaddee ====‘‘FF’’ )) ccoouutt <<<< ““ FFaaiill ”” ;;
  • 6. iiff eellssee if (( ggrraaddee ====‘‘AA’’ )) ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; eellssee iiff (( ggrraaddee ====‘‘BB’’ )) ccoouutt <<<< ““ VVeerryy GGoooodd ”” ;; eellssee iiff (( ggrraaddee ====‘‘CC’’ )) ccoouutt <<<< ““ GGoooodd ”” ;; eellssee iiff (( ggrraaddee ====‘‘DD’’ )) ccoouutt <<<< ““ PPoooorr ”” ;;
  • 7. iiff eellssee if (( ggrraaddee ==== ‘‘AA’’ )) ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; eellssee iiff (( ggrraaddee ==== ‘‘BB’’ )) …… eellssee iiff …… …… eellssee ……
  • 9. sswwiittcchh ssttaatteemmeennttss sswwiittcchh (( vvaarriiaabbllee nnaammee )) {{ ccaassee ‘‘aa’’ :: ssttaatteemmeennttss;; ccaassee ‘‘bb’’ :: ssttaatteemmeennttss;; ccaassee ‘‘cc’’ :: ssttaatteemmeennttss;; …… }}
  • 10. sswwiittcchh ssttaatteemmeennttss sswwiittcchh (( ggrraaddee)) {{ ccaassee ‘‘AA’’ :: ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; ccaassee ‘‘BB’’ :: ccoouutt <<<< ““ VVeerryy GGoooodd ”” ;; ccaassee ‘‘CC’’ :: …… …… }}
  • 11. switch statements ccaassee ‘‘AA’’ :: ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; …… ……
  • 12. EExxaammppllee sswwiittcchh (( ggrraaddee)) {{ ccaassee ‘‘AA’’ :: ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; ccaassee ‘‘BB’’ :: ccoouutt <<<< ““ VVeerryy GGoooodd ”” ;; ccaassee ‘‘CC’’ :: ccoouutt <<<< ““GGoooodd ”” ;; ccaassee ‘‘DD’’ :: ccoouutt <<<< ““ PPoooorr ”” ;; ccaassee ‘‘FF’’ :: ccoouutt <<<< ““ FFaaiill ”” ;; }}
  • 14. EExxaammppllee sswwiittcchh (( ggrraaddee )) {{ ccaassee ‘‘AA’’ :: ccoouutt <<<< ““ EExxcceelllleenntt ”” ;; bbrreeaakk ;; ccaassee ‘‘BB’’ :: ccoouutt <<<< ““ VVeerryy GGoooodd ”” ;; bbrreeaakk ;; ccaassee ‘‘CC’’ :: ccoouutt <<<< ““GGoooodd ”” ;; bbrreeaakk ;; ccaassee ‘‘DD’’ :: ccoouutt <<<< ““ PPoooorr ”” ;; bbrreeaakk ;; ccaassee ‘‘FF’’ :: ccoouutt <<<< ““ FFaaiill ”” ;; bbrreeaakk ;; }}
  • 15. ddeeffaauulltt :: ddeeffaauulltt :: ccoouutt <<<< ““ PPlleeaassee EEnntteerr GGrraaddee ffrroomm ‘‘AA’’ ttoo ‘‘DD’’ oorr ‘‘FF’’ ““ ;;
  • 16. Flow Chart ooff sswwiittcchh ssttaatteemmeenntt switch (grade) case ‘A’ : Display “Excellent” case ‘B’ : Display “Very Good” … Default : “……..”
  • 17. if ( amount >> 22333355..0099 )) ssttaatteemmeennttss ;;
  • 18. WWhhoollee NNuummbbeerr  sshhoorrtt  iinntt  lloonngg
  • 19. ccaassee ‘‘AA’’ :: ccaassee ‘‘ 330000 ‘‘ :: ccaassee ‘‘ ff ‘‘ ::
  • 20. bbrreeaakk ;; iiff ((cc ==== ‘‘zz’’ )) {{ ccoouutt <<<< ““ GGrreeaatt !! YYoouu hhaavvee mmaaddee tthhee ccoorrrreecctt gguueessss ““ ;; bbrreeaakk ;; }}
  • 22. ccoonnttiinnuuee wwhhiillee ttrryynnuumm <<== 55 ;; {{ …….. …….. ccoonnttiinnuuee ;; }}
  • 23. ccoonnttiinnuuee iinn ‘‘ffoorr’’ lloooopp for ( counter = 0 ;counter <= 100 ;; ccoouunntteerr ++++ )) {{ ………….. ccoonnttiinnuuee ;; }}
  • 24. WWhhaatt hhaavvee wwee ddoonnee ttiillll nnooww ……  SSeeqquueennttiiaall SSttaatteemmeennttss  DDeecciissiioonnss – iiff ,, iiff eellssee ,, sswwiittcchh  LLooooppss – wwhhiillee ,, ddoo wwhhiillee ,, ffoorr
  • 26. SSttrruuccttuurreedd PPrrooggrraammmmiinngg  SSeeqquueenncceess  DDeecciissiioonnss  LLooooppss
  • 27.  MMiinniimmiizzee tthhee uussee ooff bbrreeaakk  MMiinniimmiizzee tthhee uussee ooff ccoonnttiinnuuee  NNeevveerr uussee ggoottoo
  • 28. GGuuiiddee lliinneess ffoorr ssttrruuccttuurreedd pprrooggrraammmmiinngg  MMoodduullaarr  SSiinnggllee eennttrryy -- ssiinnggllee eexxiitt
  • 29. RRuulleess ffoorr SSttrruuccttuurreedd Rule 1 : Use the ssiimmpplleesstt fflloowwcchhaarrtt RRuullee 22 :: AAnnyy rreeccttaannggllee ccaann bbee rreeppllaacceedd bbyy ttwwoo rreeccttaanngglleess.. RRuullee 33 :: AAnnyy rreeccttaannggllee ccaann bbee rreeppllaacceedd wwiitthh ssttrruuccttuurreedd fflloowwcchhaarrttiinngg ccoonnssttrruuccttss.. RRuullee 44 :: IItt ssaayyss,, rruullee 22 aanndd rruullee 33 ccaann bbee rreeppeeaatteedd aass mmaannyy ttiimmeess aass nneeeeddeedd FFlloowwcchhaarrtt
  • 30. NNeexxtt MMiilleessttoonneess  DDaattaa SSttrruuccttuurreess – AArrrraayyss  CChhaarraacctteerr SSttrriinnggss  PPooiinntteerrss