# Pseudocode

Pseudocode

Pseudocode is a high-level way of putting your program into logical steps. It
uses structural conventions of programming languages, but is meant to be human
readable. It is used to help describe algorithms instruction by instruction.No
standard for pseudocode syntax exists, as a program in pseudocode is not an
executable program. Pseudocode resembles, but should not be confused with,
skeleton programs which can be compiled without errors. Flowcharts, drakon-
charts and Unified Modeling Language (UML) charts can be thought of as a
graphical alternative to pseudocode, but are more spacious on paper. Languages
such as HAGGIS bridge the gap between pseudocode and code written in programming
languages. Because pseudocode is detailed yet readable, it can be inspected by
the team of designers and programmers as a way to ensure that actual programming
is likely to match design specifications. Catching errors at the pseudocode
stage is less costly than catching them later in the development process.

Examples of pseudocode:

```Initialize total to zero
Initialize counter to zero
while the user has not as yet entered the sentinel
input the next grade (possibly the sentinel)
if the counter is not equal to zero
set the average to the total divided by the counter
print the average
else
```
```INITIALIZE Sum to 0
FOR i = 0 to array length - 1
ENDFOR
WRITE Sum
```
```CREATE array c having size = array length a + array length b
SET aIdx to 0
SET bIdx to 0
SET cIdx to 0
WHILE aIdx &lt; length of a - 1 and bIdx &lt; length of b - 1
IF a [aIdx] &lt; b [bIdx] THEN
SET c[cIdx] to a[aIdx]
INCREMENT aIdx
INCREMENT cIdx
ELSE
SET c[cIdx] to b[bIdx]
INCREMENT bIdx
INCREMENT cIdx
ENDIF
ENDWHILE

WHILE aIdx &lt; length of a - 1
SET c[cIdx] to a[aIdx]
INCREMENT aIdx
INCREMENT cIdx
ENDWHILE

WHILE bIdx &lt; length of b - 1
SET c[cIdx] to b[bIdx]
INCREMENT bIdx
INCREMENT cIdx
ENDWHILE

RETURN c
```

Pseudocode comes in all different styles. It could look based off the writer’s
preference. I will be going over how I was taught to create pseudocode and my
thoughts on the process. In later tutorials, we will be writing pseudocode for
popular algorithms used.

My thoughts on pseudocode:

I believe if we are writing pseudocode at the program level, meaning I am
writing a program’s worth of functions, rather then just one single function ,
we should specify variables at the top. Then each function should have its own
block . For an example i will write a simple program to swap integers.

```Swap integers:
variables:
x : integer
y : integer

functions:

swap:
a : void*
b : void*
create a temporary storage variable temp (void*)
set temp to x
set x to y
set y to temp

main :
print "input variable 1:"