0% found this document useful (0 votes)
13 views24 pages

Unit 2 Notes

The document discusses various programming constructs including conditional statements, loops, and jump statements. It explains the syntax and usage of if-else statements, switch-case, while, do-while, and for loops, along with examples. Additionally, it covers the break, continue, and goto statements for controlling flow in programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
13 views24 pages

Unit 2 Notes

The document discusses various programming constructs including conditional statements, loops, and jump statements. It explains the syntax and usage of if-else statements, switch-case, while, do-while, and for loops, along with examples. Additionally, it covers the break, continue, and goto statements for controlling flow in programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 24
eNr-2. Centrol Structure. Whik, Qo-whik , for, nested loops, “Conditional . Un ndjtionad a LL goto ‘ tomo Descision rakhy sot v4 fore roine L hye, Continue L q v Merete break of ; L while auiyche’ Batemans , Mi . Tn a Cordjitl onal Sfptemant, Sh Hos “of, ercenution May be. . tranferred from” one part, te , Qneuther park based on ee Otpue OF the Conditioned)! best Carried ows are has beer | surrey eat lac jet Selective Aral Loop Consyucty | S x Oh a Gelective. Constructs, tro, clatements are Selected For Seu: bared on tac Cotpute of the Condition, tose ginen Ly an ertpresion - 4 sf Sr loop Constructs, the block. of- Slatements oll be executed Tepental, unl Condition fé qaone Cle tha oop} asi) be teri : the followiry | , if, neared OE, Ste Loop Conshucts “Eifel jollewsng mentductss Bock Ae, Wht, do- while s pr J “ Me th fhe uneeditio rf KRtobements a exeutton P 6 transferee) park wit haut Carrying Cout anes Condifiand test - AL Le Osupporto tho pebowiag ee as gote, brealc, Contiwe >. +, Hak ements - ZWEI sion Zt lotemen | | oh idhas, Glod-ement, Ww dee erepradision. | je tau \ the block of slabemeniA ave \ execebed othernsive false and ib Comes | OW OF the th lendifion « Syntax! if c¢ ercpress ion 2 “block, of sbaverlent™s? (& Program tp find) the giver rember ia diwsible by 2. +#/ Hinclude o) : printf (" \w The Given number yd) IA 5 positive’, n), ele, Yi “\n iver syd et \ Fe Sabie’, 5 ) Durpe t. 7! Emer che humber /5 The given Number & to Fost ive . lend itionad ge rcpression HThe texncry Operator Fe vaste} to, Wed to form a Conditional Expression . : 3b Th Wes Here three’ operands And hence Tt Js Called as a berreny Operator - Sdntax ! ~< expression | > ? AEexpression 2h; . x expression 3> > Flowchart. . ‘ ; Uifele Ip, stabemant | Sf the expression | SA tne, Sjotement J wil) be excused, Otherwise tha CPrecsion 9 [A C\nluated, it jk bs tie athe Statements fa exrecuced, otherwise tHe Sxpreciong ps e@ wl, tr PETA bhuc then Shetemenn3 4 exeuted , otkerwis 2 Statement 4 Tb Crxcured . a Pregram who fine tha: Stuclens Clagy for the ‘given | Averge | marks valing [f-ebo ff #/ Hrinclucle. <8thioh> ial mained veld main cd Int Ng mark} Print Center the ee park :” Scent ("y 4" K Avg mark)’ SFC A\9- mark Ss %s) t oe wy atyn TVD. prine$ ¢ ‘D feerpction 3 1 else: TEC AVG marks 260) ak CAVG trees) Princ$ (“Pinst chacz); j as clerf (CAVg_ mark +250) && (Avg_ mark = 4s) 89 Cg monk ad rain 6. J : Xe vee “a, y, Z3 Printf (" Nn Enter the. three. —_ bee ers 7 Scant Ong yd ud , “ Bx, &y, ke) _ COmy) KK Mr) ) PMCS ("the Biggest number 2 vd) x) 5 3 ; ele t v if Cyex) WT NL " . i 4 P FOO The Biggesr numbers = vd" yy 3 elke Zé Prine (“The Biggast humber = %d", KL 5 5 getch oy vi 3. o Le! Enter the three numbers, 5 28 The Biggest heumber =&' _Suitch cd Case Statement + the. gwitth case §& nae multiple branching Crude jple Aecision making ) Atotemert, The witch statement Ack a Particulay Groep Top oy 6 from Several Orvaileble freup. - Syntax: euitch Cecp) { Case. Consh tl! Cfoabomant Ij break Case Const 4° ol albomant Le i ibreakey aus — Ae fault atemant 4 break } ia Flow chart: Coston) . He Inlet ’ Veicl maincs t Int ab, 2 Chay OP: Prine ("4 pce! \y ~Sub Vo, % “ee rt We Printé ("Enter the Case vole), Scanf c" “ ve", Op); PYiIMtE Center tne voles") Scen$ Cd ya "ka, abs Switch Cop) Case ‘- C= ate; . \break; Case =f: Cs ab breatc: \ Case \” C= axes, » ae breale > Woe \ 3 L\Prinet Co Resute = vd "e) » 4 od Lesping Stoboment:: fi “ofp loop Is olefined as Statements cick, Cxetked for time - a bloc rep Cerjain Number Of are. 1 wshil Statements \ “atolo-while Gfarement 3 for Statement while spatement! of The. while Leop | fa fen Lisedl when the pumber of timed the Loop PS eto be excecured fs rok Known fra qelvence . , ve 4 A Sequence of ctate nent A Qre Oxeured| until Some Condition [4 Satistied | Syntax. while Gonditon ) blect: OF statements; nee’ mentation l dlecremantation ; ES pouchitis a Melle < S4elio-hy Veiel maine) ° ee folie t. i Int nee ; \ wh le Ches5) vel y t uw Prince (“Yel “ands OC NHS \ a? a + The ke... while oop PA an a Contrellect stop because re test Conbliton TA Cvaluareds at the end 4% The booly of the lep gers Cxreeuted atlas One time She tes Cendifien must be terminated by (59 Semiccer fn clowhile teop — _— ' asd yal Symyx do L Stabemenks: 3 tuhila (Condtion) + Example ‘4 . ptinclide: 2Stdio- hs Void mainc) : Ine Neel ao gen printhGtd., Rn); nH; ; while Cn 2e5)" t For‘ coop: bodies Sf “4 SEN Ss oft Ps definite Uoop . TE T4 led to execute QQ: Sot of fnstucHony vepeaticlly , until the Condition . become False . Syntax for jnttialixnrtio, condition; increment /decrn bedy of Atotemenrs: Flowchart : a Mplimcion | iene Bherement / SQ deérement || = “ ates i) 1 Htlnclucle < Stelio-h'y + Vebl maine) Ine 75 fore; fees; lH) popet C" xd a Ri); Fo Nested) for loop! y The. Joop — ustthin the. heste cep. Y The humbey of Thewntions fh Chic type Of structure. is equal te ane number OF Thevessions Fo Soe bey loo malbiplied § ° Ehe rember, oF fons ions In oun eep, Bxomple Progen. Hinchide 2&4di0+h 2 Void maine) fou. Jot Jydae for Cizga; F428 itt) Ss Loop PA cay printh ("ne DG for Car; Je=32 JH) Print ("yd " 4); QnCarctibional_ Clatomants: et latent Jamp stabements: fy AN Unceclitona) Stabemenr fn c fea Stoement ther ja exeuted eves cime the Programs 'Con 4yon] reaches te, without Checking any Conclitien OF Yequivereey Desires ‘ fe: KA Un eaditfonal ~~ Gkabemenc V4 Progremming To structions thar fs 4 exreuzed In hequence luring Pregen ex eatin, Yegardles of Ay fprdizien os decision. TENS Ved Types Of Jump shaterente: |. break, : 2. Continue 8. Goto ~ 4. retnrn . break : es 7 break Chatement ee \ A of tha Loop © anal thet: ‘aaah ips frantdorred # the Hoke po fn inediately Jollousiney wthe Loop WK The . break Gtakement | does not have any Beobb embedded een OY arguments. Sgntaxy break ; Exarrple ! 4 . (#° Preqrac be clowonshrate he ‘bre chetemene ¥| Hiicude. 4.sddio. Ay \Vorof fain cd ig per for Cea y Vactos HAY" £ . if Ci==5) breaty re prince £0 %%4 , AID 4 Getech oO: . Aus abi sot ; Corina \Mhomeniane ‘ll The" Continue , +9 4p) Ramet FA Use te transfer. the Control ‘#0 the sbesiky of the. Loop . ro dom Mothe.. cLeop does nok! Leniinake ighen a tootiruce. eee TA En countered . . ™ ¥ TM Stead | the Temanng Lop, sulaeds Pa aye Skipped and the Coro putats ie directly bo the next pass thragh Loop, INtAaK : Continue: OE Progreso to demonshate thee Continua! fate ment + /. ARincude — Stohio. hy Void maine) is) oe , \ »dnk J Sum co) 73s vee for Get 3 Szslo; MH) hddeang an £ it CCiy2)) =0)) Continue} Le 3 Sum = Sum +i. Prine $ C the. Suro, = hel” Sur) > aN 4A a4 \ Goto Sstotemenk : abontent “Bed The. goto Sfabemunt eo. of ee the hornet Sequents ram cerecuibion Un ce onal, fs che tonpol te Smee other tranégferri ’ ba Pork of the Pega i Syuax: oi} ee Goto abel? bbntihe?? alias oY , fs an sda Te er ite which the Lonel 108 bentferred - , . be ob ntbeng 4 The Conol to ae Makemant within tha, can g paction. tush Staroment be ‘gna ott it rast be” fallowed a Qa Colon’- Example “Th progam tS demanchate the Jo to Starement ¥ / elnclude £ addlion hy sptelinchide 2 Lonio- hy aa main C) jak bay Clrsercy Princ £ (" Enter ethe Number :""); Scant c* nd" &x)3 HF Cx x2 220) Owkput Enter theinumbey Son's odd number , geto Odol even : Print f(" \n zd # Iso an even umber"); wekurn 5 : ) Ode : | \ : Cos Printt$C"\n ud fa con, edd punter"), 3 o , Sebwrn 3 The Yetum atomenr fa © fa heed bo bexminate the execution G a function And vetmn a Vedue ubo the caller. 3 te S45 Commonly wed to Pratcle cc Teste back be the cabling Coole . —Buntax Yeturn exprension ; ier Htinclucde 2 “tdiohy Int add Cine & , ine b) Ing Gam = ate? \. eae Slum 5 \ 7 rau re | a | Veiel Prine message C> Prine$ (“ WeLlome CSe "BoD ine Main c) t. , {a tae vehulie = adel CS, 3) Pring $0" Reade © Yol An BR veaude); Priaie mMenagec); 4 vetuin 2) ae | dy | : plac ia.

You might also like