Per my last post, we began discussing pseudocode and flowcharts. In this post, I wanted to further explain best practices and tips for creating them.
Flow Control Methods
Pseudocode should always follow a specific flow structure, whether it is sequential, selection, loop, call, etc. While the following examples are not a specific and correct code, they are intended to give a general idea of how it all works (which is exactly what pseudocode does).
Program code performed in the listed order.
- Input first number
- Input second number
- Subtract second number from the first number
- Display the difference
The flow of the program is indicated either by choice or a value comparison.
- Input number
- Check if number is equal or less than a specific number (if it is, then a specified criterion is met)
- If the number is not equal or less than a specific number, then a specified criterion is not met
- End IF
- Continue program flow
Controls the number of times a specific call or sub-routine will execute before the loop ends. Without a loop, the sequence would continue indefinitely.
- Perform a task if input is correct
- Do not perform a task if input isn’t correct (but loop back to task 1 until it is correct)
- Once input is correct, initiate program
Commonly referred to as sub-routines or method calls, these are typically embedded within the program. When a call or subroutine is instructed to execute, the flow is interrupted to start the designated method or sub-routine call.
- Call by value- Argument is checked, copied, and passed to the subroutine.
- Call by reference- Refers to the argument, the address is passed.
- Call by result- Value is copied back to argument on return from the subroutine.
- Call by name- Operates similar to a macro. Replaces parameters with unevaluated expressions.
For an example of how this flow operates, I have created what looks like a simple Sequential flow pseudocode, however, if you notice on step 5, there is a setting to have it Loop, which controls how many times the code will execute; below that is this pseudocode’s flowchart.
- The even numbers between 20 and 40
- Put in the number 20
- Add 2 to the number
- Output the number
- If the number is less than 40, go back to step 3
Categories: Operating Systems/Programming