[Home]Pseudocode

HomePage | Recent Changes | Preferences

Difference (from prior major revision) (minor diff)

Removed: 14,15d13



Removed: 29,40d26
Note that == (double equal sign), not =, denotes equality;
this distinguishes it from the assignment =.
An optional colon (':') after the condition improves readability.

Functional conditionals:

if <condition>
value
else
other value



Removed: 62,70d47
Where it is necessary to distinguish between passing arguments by value or by reference, describe it in English.

Long program lines:

do something that takes a lot of text to describe, and if it doesn't
fit on one line, continue it indented at least two levels
(four spaces) inward



Removed: 74,75d50
declare <variable-name> as <type> = <initial value>
declare <variable-name> as array [<lower-bound> to <upper-bound>] of <type>

Changed: 78,83c53
type should be an english word or phrase describing the type

Lower and upper bounds can be integers or chars.
Note that an array declared [0 to 10] would have eleven elements: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10.

Creating your own types:
Array declarations:

Changed: 85,87c55
class <name_of_new_type>
<variable declaration(s)>

declare <array-name>[<lower-bound> to <upper-bound>] of <type>

Changed: 90,92c58,62
A "class" is a record containing variables called "fields" and optionally functions called "methods" that have an implied argument 'this'.
Names of classes most often begin with a capital letter.
An "object" is any variable whose type is a class.
Composite data structures (also see Object Oriented Programming):

struct <name_of_new_type>
<declaration(s) of internal variables>


Changed: 94c64
Example of accessing fields and methods of an object:
Accessing fields of a composite structure:

Changed: 96,98c66
declare grohl as Foo
...
var = grohl.height
<structure variable name>.<field name>

Pseudocode is a generic way of writing source code without using any specific programming language. (However, some people see standardized pseudocode as languages in and of themselves.) Computer science text books often use pseudocode in their examples so that all programmers can understand them, even if they do not all know the same programming languages.

Often pseudocode uses the syntax of one common language (like C or LISP) for common operations like loops, and uses English language text whenever details are unimportant or distracting.

Pseudocode in Wikipedia

Many articles in Wikipedia use pseudocode to demonstrate how an algorithm or data structure works.

Our style of pseudocode uses keywords from C for the some common operations, and, like Python, uses indentation to distinguish the scope of things like loops.

Example operations

Assignment:

<variable> = <expression>

Conditionals:

if <condition>
  do stuff
else
  do other stuff

Simple loops:

while <condition>
  do stuff

for <variable> from <first value> to <last value> by <step>
  do stuff with variable

Function calls:

<function>(<arguments>)

Function declarations:

function <function name>(<arguments>)
  do stuff with arguments
  return something (optional)

Variable declarations:

declare <variable-name> as <type>

Array declarations:

declare <array-name>[<lower-bound> to <upper-bound>] of <type>

Composite data structures (also see Object Oriented Programming):

struct <name_of_new_type>
  <declaration(s) of internal variables>

Accessing fields of a composite structure:

<structure variable name>.<field name>

This standard still needs work. Care to /Talk ?


HomePage | Recent Changes | Preferences
This page is read-only | View other revisions
Last edited October 1, 2001 1:27 pm by BlckKnght (diff)
Search: