Pseudo code:

  • Pseudocode is written in a human-readable format, often using plain English or a language similar to a programming language.
  • It focuses on the algorithm’s logic and structure, rather than precise syntax details.
  • It’s used for planning and understanding the flow of a program or algorithm.

Examples:

1

# APCSP Pseudo-Code: Iterating Over a List of Fruits

# Create a list of fruits
fruits  ["apple", "banana", "cherry"]

# Iterate over the list and display each fruit
FOR EACH fruit IN fruits:
    DISPLAY "I love " + fruit
END FOR

  Cell In[1], line 4
    fruits ← ["apple", "banana", "cherry"]
           ^
SyntaxError: invalid character '←' (U+2190)

2

# College Board Pseudo Code for lists
aList  []

USER_INPUT  ("Enter an item you want (or 'q' to quit): ")

REPEAT UNTIL USER_INPUT  q{
    APPEND (aList, USER_INPUT)
}

DISPLAY(aList)

  Cell In[2], line 2
    aList ← []
          ^
SyntaxError: invalid character '←' (U+2190)

3

# CB Pseudo Code

A  true
B  true

IF (A AND B) {
   DISPLAY("It's true!")
}
  Cell In[3], line 3
    A ← true
      ^
SyntaxError: invalid character '←' (U+2190)

4

#Example of procedure
A 60$ item recieves a 20% discount and taxed at 8%.
PROCEDURE applyDiscount(cost, percentDiscounted)
{
    temp  100 - percentDiscounted
    temp temp/ 100
    cost  cost *temp
    RETURN(cost)
}

price  applyDiscount(60, 20)
This is how we get the final price with the discount by calling the procedure and assigning it to the price variable.


PROCEDURE applyTax(cost, percentTaxed)
{
    temp  100 + percentTaxed
    temp temp/ 100
    cost  cost *temp
    RETURN(cost)
}
price  applyTax(price, 8)
This applys the 8% tax to the price determined after the discount.
  Cell In[4], line 5
    temp ← 100 - percentDiscounted
         ^
SyntaxError: invalid character '←' (U+2190)