DOC PREVIEW
IUPUI CSCI 23000 - Program Control

This preview shows page 1-2-14-15-30-31 out of 31 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 31 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Slide 1OutlineStructured Program DevelopmentControl StructuresControl Structures (cont.)Semantics vs SyntaxSelection Structure: ifThe if Selection Structure (cont.)Selection Structure: if/elseThe if/else Selection Structure (cont.)Slide 11Slide 12Repetition Structure: whileSlide 14The Essentials of RepetitionEssentials of Counter-Controlled RepetitionRepetition Structure: forThe for Structure (cont.)The for Structure (cont.)Multiple-Selection Structure: switchSlide 21Slide 22Repetition Structure: do/whileSlide 24The break and continue Statementscontinue Statementbreak StatementEquality (==) vs. Assignment (=) OperatorsExamplesExamples:Slide 31Dale RobertsProgram Control- C StatementsDepartment of Computer and Information Science,School of Science, IUPUIFall 2003CSCI 230Dale Roberts, LecturerDale Roberts, [email protected]@cs.iupui.eduDale RobertsOutlineOutlineThis Topic IntroducesThis Topic IntroducesStructured Program DevelopmentStructured Program DevelopmentSelection StructureSelection Structureififif/elseif/elseAdditional repetition control structuresAdditional repetition control structureswhilewhileforfordodo//whilewhileswitchswitch multiple selection structure multiple selection structurebreakbreak statement statementUsed for exiting immediately and rapidly from certain control structuresUsed for exiting immediately and rapidly from certain control structurescontinuecontinue statement statementUsed for skipping the remainder of the body of a repetition structure and Used for skipping the remainder of the body of a repetition structure and proceeding with the next iteration of the loopproceeding with the next iteration of the loopDale RobertsStructured Program DevelopmentStructured Program DevelopmentBefore writing a program:Before writing a program:Have a thorough understanding of the problem Have a thorough understanding of the problem Carefully plan an approach for solving itCarefully plan an approach for solving itWhile writing a program: While writing a program: Know what “building blocks” are availableKnow what “building blocks” are availableUse good programming principlesUse good programming principlesAlgorithmsAlgorithmsComputing problems Computing problems All can be solved by executing a series of actions in a specific orderAll can be solved by executing a series of actions in a specific orderAlgorithm: procedure in terms ofAlgorithm: procedure in terms ofActions to be executed Actions to be executed The order in which these actions are to be executedThe order in which these actions are to be executedProgram control Program control Specify order in which statements are to executedSpecify order in which statements are to executedDale RobertsControl StructuresControl StructuresPseudocodePseudocodeArtificial, informal language that helps us develop algorithmsArtificial, informal language that helps us develop algorithmsSimilar to everyday EnglishSimilar to everyday EnglishNot actually executed on computers Not actually executed on computers Helps us “think out” a program before writing it Helps us “think out” a program before writing it Easy to convert into a corresponding C++ programEasy to convert into a corresponding C++ programConsists only of executable statementsConsists only of executable statementsControl StructureControl StructureSequential executionSequential execution Statements executed one after the other in the order writtenStatements executed one after the other in the order writtenTransfer of controlTransfer of controlWhen the next statement executed is not the next one in sequence. Ex: When the next statement executed is not the next one in sequence. Ex: gotogotoOver use of Over use of gotogoto statements led to many problems statements led to many problemsneed to eliminate need to eliminate gotogoto statement statements1s2s3... sncontrols1s2s3...si...sj...sncontrolDale RobertsControl StructuresControl Structures (cont.)(cont.)All programs written in terms of 3 control structures All programs written in terms of 3 control structures (Bohm and Jacopini)Sequence structures:Sequence structures: Built into C. Programs executed sequentially by default Built into C. Programs executed sequentially by defaultSelection structures:Selection structures: three types: three types: ifif, , ifif//elseelse, and , and switchswitchRepetition structures:Repetition structures: three types: three types: whilewhile, , dodo//whilewhile and and forforFlowchart Flowchart Graphical representation of an algorithmGraphical representation of an algorithmDrawn using certain special-purpose symbols connected by arrows called Drawn using certain special-purpose symbols connected by arrows called flow-linesflow-linesRectangle symbol (action symbol):Rectangle symbol (action symbol):Indicates any type of actionIndicates any type of actionOval symbol:Oval symbol:Indicates the beginning or end of a program or a section of codeIndicates the beginning or end of a program or a section of codeSingle-entry/single-exit control structures Single-entry/single-exit control structures Connect exit point of one control structure to entry point of the next (control-Connect exit point of one control structure to entry point of the next (control-structure stacking)structure stacking)Makes programs easy to buildMakes programs easy to build…ControlStructure1ControlStructure2ControlStructure3Dale RobertsSemantics vs SyntaxSemantics vs SyntaxEvery language embodies the concepts of semantics and syntax. Every language embodies the concepts of semantics and syntax. Semantics is the meaning behind what is being said.Semantics is the meaning behind what is being said.Syntax is the structure of how something is being said.Syntax is the structure of how something is being said.The rules of grammer are the syntax for English.The rules of grammer are the syntax for English.Two different syntaxes can have the same semantics.Two different syntaxes can have the same semantics.Different sentences with same meaning should have same Different sentences with same meaning should have same meaning:meaning: 1. John gave the book to Mary. 1. John gave the book to Mary. 2. The book was given to Mary by John. 2. The book was given to Mary by John. Both:Both: give-action: agent: john give-action: agent: john object: the book object: the book receiver: maryreceiver: marySame the semantics of control structures applies to every computer Same the semantics of control


View Full Document

IUPUI CSCI 23000 - Program Control

Download Program Control
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Program Control and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Program Control 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?