DISPLAY(gossip())if it's written as text or if it's shown as blocks.
You won't have to be able to write code in this notation on the AP exam. You just have to be able to read it so you can answer questions about it.
PROCEDURE double(x) { RETURN(2 * x) }
Many languages (and the AP CS Principles Exam) use return
instead of report
as the name of the command to give a value back at the end of a function call.
double(5)" means 10.
RANDOM(1, 10)or . Every time you run this code, you will get a different random number between 1 and 10.
pinwheel
commandPROCEDURE pinwheel(numberOfBranches) { REPEAT numberOfBranches TIMES { move(100) move(-37) turn_clockwise(360 / numberOfBranches) } }
move()and
turn_clockwise()aren't built in to the AP's language so they are written in lower case like other programmer-defined procedures.
PROCEDURE pinwheel(numberOfBranches). The word
PROCEDUREtells you that that line of the code is like a hat block; the variable name in the parentheses on that line is the input that the procedure takes.
Pinwheel(6, 80, 20)or .
You may hear people use the term "pseudocode" to refer to this pseudo-language used on the AP CS Principles exam, but it's not pseudocode. Pseudocode isn't a programming language at all, it's the use of normal human language to describe an algorithm.
mouse y
, which isn't built into their language). So this example translates them to numFishand
MouseY().
()or box after
MouseYis that
MouseY()is a procedure call even though it doesn't take any inputs.
The script
would be written as
REPEAT UNTIL(mouseY() < 0) { DISPLAY(numFish) }
Remember, you don't need to learn to write the made-up language used on the AP exam. You just have to be able to read and answer questions about it.