How to Write a Pseudocode Loop
By Finn McCuhil
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
References
Tips
- Use common words like "print" instead of function names like "cout>>" to keep the code clear. Leave specific functions and data handling methods for the language-coding phase.
- Write program prototypes in pseudocode for greater flexibility in choosing a final language for the project. Using English only allows you to transfer the program's basic logic to almost any development platform.
Writer Bio
Finn McCuhil is a freelance writer based in Northern Michigan. He worked as a reporter and columnist in South Florida before becoming fascinated with computers. After studying programming at University of South Florida, he spent more than 20 years heading up IT departments at three tier-one automotive suppliers. He now builds wooden boats in the north woods.