Just like with making decisions in a Flowcharts, you can easily make decisions with Pseudocode.
Decisions once again need to be in a simple yes/no
or true/false
style format. Remember, computers are stupid, so we must keep things simple for them.
To create a decision, we typically need our condition, and then a body. Since we don’t have flowlines like we do with a flowchart, we need to find a way to make it easy to identify what part of our pseudocode is part of the conditional body, and what part is outside. The easiest way I’ve found is to indent the part of the code which will be inside of the conditional body. I will also often use blank lines to separate blocks of logic to make it easier to read.
Our conditional question usually starts with if
then has the condition and then a then
statement. We could read it as if condition then…
Here is an example:
if age >= 16 then
print "You can get your driver's license."
program ends
What if Condition is Not True
Well, this depends. Sometimes we will do nothing, and just bypass that portion of code. However, if we want to do something, we’ll use a word like else
. Else will let us know that there are things to do if the condition was not met.
Once again, we would indent the else block, so we know when it ends
if age >= 16 then
print "You can get your driver's license."
else
print "You cannot get a driver's license yet."
program ends
Pseudocode Decisions was originally found on Access 2 Learn