Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Structured programming
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Elements== ===Control structures=== Following the [[structured program theorem]], all programs are seen as composed of three [[control structure]]s: * "Sequence"; ordered statements or subroutines executed in sequence. * "Selection"; one of a number of statements is executed depending on the state of the program. This is usually expressed with [[Keyword (computer programming)|keyword]]s such as [[Conditional (programming)|<code>if..then..else..endif</code>]]. The conditional statement should have at least one true condition and each condition should have one exit point at max. * "Iteration"; a statement or block is executed until the program reaches a certain state, or operations have been applied to every element of a collection. This is usually expressed with keywords such as [[While loop|<code>while</code>]], [[Do while loop|<code>repeat</code>]], [[For loop|<code>for</code>]] or [[Do while loop|<code>do..until</code>]]. Often it is recommended that each loop should only have one entry point (and in the original structural programming, also only one exit point, and a few languages enforce this). [[File:Structured_program_patterns.svg|thumb|649x649px|center|Graphical representation of the [[structured program theorem|three basic patterns]] — sequence, selection, and repetition — using [[Nassi–Shneiderman diagram|NS diagrams]] (blue) and [[flow chart]]s (green).]] ===Subroutines=== [[Subroutine]]s; callable units such as procedures, functions, methods, or subprograms are used to allow a sequence to be referred to by a single statement. ===Blocks=== [[Block (programming)|Blocks]] are used to enable groups of statements to be treated as if they were one statement. ''Block-structured'' languages have a syntax for enclosing structures in some formal way, such as an if-statement bracketed by <code>if..fi</code> as in [[ALGOL 68]], or a code section bracketed by <code>BEGIN..END</code>, as in [[PL/I]] and [[Pascal (programming language)|Pascal]], [[whitespace character|whitespace]] indentation as in [[Python (programming language)|Python]], or the curly braces <code>{...}</code> of [[C (programming language)|C]] and [[Curly brace family#Curly-bracket languages|many later languages]].
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)