Download presentation
Presentation is loading. Please wait.
1
Nate Brunelle Today: Pseudo-Code, Party
CS1110 Nate Brunelle Today: Pseudo-Code, Party
2
Questions?
3
Course structure Concepts “Turtle”
4
Ambiguity “Put the pot in the dishwasher”
What we say to computers: Instructions How to wash your hair? How to wash your hair: Lather rinse repeat
5
How to wash you hair: repeat: lather rinse Lather Repeat:
6
How to wash you hair: repeat 3 times: lather rinse How to lather: wet your hair put shampoo in your hand repeat until hair is foamy: rub your hand through you hair
7
Pseudo-Code Code: write things in a way a computer can understand
Pseudo- Not quite Pseudo-Code: Not quit write so that a computer can understand Good for expressing things unambiguously But still using English to gloss over the details
8
Conditionals What if I’m out of shampoo? How to wash hair:
if you are out of shampoo: get more shampoo repeat: lather rinse
9
Rules of Pseudo-Code Sequence = Do the highest line first, then perform them in order from top to bottom Line = one “thing” to do Repetition = repeat something Fixed number of times : e.g. “repeat 3 times” Until something happens: e.g. “until hair is foamy” Conditions/Decisions = maybe do something Check something first If there is no more shampoo, then get more Named actions = two parts: definition, use Definition = how to do a thing Use = when to do the thing defined
10
Party Repeat 2 times: Sing “Happy Birthday to you” Sing “Happy Birthday to Nathan” Sing “Happy Birthday to You” Clap
11
Do this Repeat 2 times: stand clap sit
12
Brush your teeth Write pseudo-code instructions for brushing your teeth Share with your neighbor, who will try to find a problem with it Remember: Sequence Repetition Conditionals Named Actions
13
3x+1 Let x be your age in years let count start as 0 Repeat as long as x is not 1: add 1 to count if x is even: divide x by 2 otherwise: multiply x by 3 and add 1 Clap “the count” many times
14
Variables In Math: In Statistics: In Programming:
A name that refers to a particular value In Statistics: A name for a thing that has one value, but we don’t know what it is In Programming: A named value that can vary over the course of doing something x is a variable in the previous slide
15
Problem Programs cannot “reflect” on what they did
Let x be your age in years Let “count” = 0 Repeat as long as x is not 1: add 1 to “count” if x is even: divide x by 2 otherwise: multiply x by 3 and add 1 Clap “count” many times
16
Bugs Syntax Semantic Logical Understandability
Statement does not “parse” Semantic Grammatically correct, but nonsense Logical Means something, but not what you meant Understandability I said it, it makes sense, and it means what I meant, but no one else can understand it
17
Syntax Semantic Statement does not “parse”
Dog of by chicken for running video the W202dkdljdkla9**ls Semantic Grammatically correct, but nonsense Colorless green ideas sleep furiously Park your car upon the cloud. 3 0
18
Logical Understandability Means something, but not what you meant
“double 5” vs “5+2” Understandability I said it, it makes sense, and it means what I meant, but no one else can understand it The sign should have dashes between fish and and and and and and and and and chips. Prandial soleation is gauche.
19
“Homework”
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.