1 / 16

Structured Programming The Basics

Structured Programming The Basics. Structured Programming. Early programmers had to learn to program ad hoc – try things and see if they worked Early software engineers studied software projects to see why some succeeded and some failed

gwalters
Download Presentation

Structured Programming The Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Structured ProgrammingThe Basics

  2. Structured Programming • Early programmers had to learn to program ad hoc – try things and see if they worked • Early software engineers studied software projects to see why some succeeded and some failed • They found patterns of programming that usually give good results when followed • These are the rules of structured programming

  3. Control Structures and Data Structures • Control structures and data structures are the main components of any program • Data structures allow you to access your data • Simplest is a literal constant like 5 • Variables are simple data structures – have a name, a value, a type, a location (address) in RAM • Lists, files, graphics objects are more complex data structures

  4. Control structures • They control the order of execution • What order statements will be done in, or whether they will be done at all (whether they are skipped or not) • Different from data structures

  5. Why do structured programming? • It's easier to understand code written using structured programming • Easier to test and debug code • Easier to modify and maintain code • Easier to work with other people to write large programs

  6. 4 Control Structures • Sequence • Selection • Iteration • Module

  7. Guarantees for All Structures • ONE Entrance • ONE Exit

  8. SEQUENCE . . . Statement 1 Statement 2 Statement 3

  9. Guarantees for Sequences • Will execute the steps in the order given • Will not enter or leave sequence in mid-stream • Will not skip steps

  10. SELECTION(branch) IF Condition THEN Statement1 ELSE Statement2 True Statements1 Statement Condition . . . Statements2 False

  11. Selection Guarantees • Control always enters through the condition / question • One branch or the other is executed, never both on one run • MUST execute one branch or the other • Processes in branches can be as large or small as you want • Do not write Dead Code!

  12. Dead Code

  13. Body LOOP(repetition) WHILE Condition DO Statement1 False . . . Condition True

  14. Guarantees • Will go through test / condition at top to get into loop • ALL of body will be executed before test is done again • Body will be repeated until test is answered differently (NO) • Do not write Infinite Loops! (usually a logic error in the controlling condition at the top)

  15. SUBPROGRAM(function) . . . SUBPROGRAM1 SUBPROGRAM1 a meaningful collection of SEQUENCES, SELECTIONS, LOOPS, SUBPROGRAM calls

  16. Module Flow of control

More Related