How to Write a Pseudocode Loop

By Finn McCuhil

Diagram program flow in English before translating it into code.
i Comstock/Comstock/Getty Images

Pseudocode is a programming shorthand language that uses standard English to represent actual program calls and statements in order to speed up program development. Test logic and program flow before you write the actual statement and individual functions for your next program. Writing pseudocode makes it easier to follow the intended program flow and allows you to spot basic design flaws. Use the code to explain each loop's type and what it should accomplish in the program.

Step 1

Code an "if" loop. For example:

if the inventory level is above minimum

print "inventory good"

else

print "order more"

Step 2

Code a "while" loop. For example:

set the total to zero

set the month counter to one

while the month counter is less than 12

input monthly price

add monthly price to total

set the average price to total divided by 12

print "The average monthly price is result"

Step 3

Code a "for" loop. For example:

set the counter to zero

exit when the counter reaches 6

increment the counter

list the days of the week in an array (0 through 6)

print the day of the week based on the array number

×