Describe the disadvantages of unstructured spaghetti code
Spaghetti code - Logically twisted program statement, complicated mess
Programs work, but are difficult to read and maintain, confusing and prone to error
Unstructured programs - do not follow rules of structured programs
Structured programs - do follow the rules of structured programs
Describe the three basic structures
Structure - Basic unit of programming logic
Any program can be constructed using one or more of these three structures
Sequence structure
Perform actions in order
No branching or skipping any task
Selection structure (decision structure)
Ask a question, takes one of two actions (only true or false)
Also, decision structure or selection structure
Boolean expression- decision statement (if)
Dual-alternative ifs or single-alternative ifs
contains two alternatives (if-then-else endif)
contains only one alternative (if-then endif) else not required (if it rains then take an
umbrella)
null case - situation where nothing is done (if it does not rain, do nothing)
end structure statement- endif
Loop structure
Repeat actions while a condition remains true
Loop body- actions taken within loop
also called repetition or iteration
condition tested first in most common form of loop
(while...do) or (while) loop
Combining structures
Structures can be combined in an infinite number of ways
Any individual task or step in a structure can be replaced by a structure
Stacking structures - attaching structures end-to-end
End structure statement- indicates end of structure (endif) (endwhile)
Nesting structure - placing one structure within another, indent the nested structure's
statements
Block - a group of statements that execute as a single unit