High Level Pseudocode

Objectives

  • learn what pseudocode is
  • learn how to use it to break down problems into discrete operations

Context

High-level pseudocode is used to break a large general probelm into smaller chunks / operations / statments about what the computer should do next.

Pseudocode example: Pour water into a glass

Instruct a robot to pour water from a bottle into a glass.

Exercise: How to Make a PB&J Sandwich (10 minutes / 0:15)

Pair up and write down your pseudocode.

**Here's one approach to solving our problem** ``` PROGRAM MakePB&JSandwich: Grab a paper plate; Open bread container; Grab bread package; Untwist bread package; Open bread bag and remove two slices; Place slices on paper plate; Grab a plastic knife; Open peanut butter jar; Use knife to scoop out peanut butter; Apply peanut butter to one slice of bread; Spread peanut butter on slice; Place knife on plate; Close peanut butter jar; Open jelly bottle; Squeeze jelly onto second bread slice; Close jelly bottle; Place down jelly; Pick up knife; Spread jelly on slice; Bring two slices of bread together; Cut slices in half down the middle; Throw knife in the trash; Pick up one half of sandwich; Enjoy; END. ``` > A. This example's sequence is very thorough! However, we are still assuming certain conditions that our utensils or ingredients already exist. What if we are out of plates? Will we grab a napkin instead to place our sandwich on? What if we are out of jelly? Will you throw the sandwich away or eat it with just peanut butter?

results matching ""

    No results matching ""