100% found this document useful (1 vote)
3K views6 pages

Ap Computer Science Principles Exam Reference Sheet

Uploaded by

api-199294806
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
3K views6 pages

Ap Computer Science Principles Exam Reference Sheet

Uploaded by

api-199294806
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CSP Exam Reference Sheet

Instruction Explanation
Assignment, Display, and Input
Text: Evaluates expression and then assigns a copy of the result to
a ← expression the variable a.
Block:

a expression

Text: Displays the value of expression, followed by a space.


DISPLAY(expression)

Block:

DISPLAY expression

Text: Accepts a value from the user and returns the input value.
INPUT()

Block:
INPUT
Arithmetic Operators and Numeric Procedures
Text and Block: The arithmetic operators +, -, *, and / are used to perform
a + b arithmetic on a and b.
a - b For example, 17 / 5 evaluates to 3.4.
a * b
The order of operations used in mathematics applies when evaluating
a / b
expressions.
Text and Block: Evaluates to the remainder when a is divided by b. Assume that
a MOD b a is an integer greater than or equal to 0 and b is an integer
greater than 0.

For example, 17 MOD 5 evaluates to 2.

The MOD operator has the same precedence as the * and /


operators.
Text: Generates and returns a random integer from a to b, including
RANDOM(a, b) a and b. Each result is equally likely to occur.
Block:
For example, RANDOM(1, 3) could return 1, 2, or 3.
RANDOM a, b

Relational and Boolean Operators


Text and Block: The relational operators =, ≠, >, <, ≥, and ≤ are used to test
a = b the relationship between two variables, expressions, or values. A
a ≠ b comparison using relational operators evaluates to a Boolean value.
a > b
a < b For example, a = b evaluates to true if a and b are
a ≥ b equal; otherwise it evaluates to false.
a ≤ b

AP Computer Science Principles Exam Reference Sheet    | 1


 V.1 
© 2020 College Board
Instruction Explanation
Relational and Boolean Operators (continued)
Text: Evaluates to true if condition is false; otherwise
NOT condition evaluates to false.
Block:
NOT condition

Text: Evaluates to true if both condition1 and condition2


condition1 AND condition2 are true; otherwise evaluates to false.
Block:

condition1 AND condition2

Text: Evaluates to true if condition1 is true or if


condition1 OR condition2 condition2 is true or if both condition1 and
condition2 are true; otherwise evaluates to false.
Block:
condition1 OR condition2

Selection
Text: The code in block of statements is executed if the
IF(condition) Boolean expression condition evaluates to true; no
{ action is taken if condition evaluates to false.
<block of statements>
}
Block:

IF condition

block of statements

Text: The code in first block of statements is executed


IF(condition) if the Boolean expression condition evaluates to true;
{ otherwise the code in second block of statements is
<first block of statements> executed.
}
ELSE
{
<second block of statements>
}
Block:

IF condition

first block of statements


ELSE
second block of statements

AP Computer Science Principles Exam Reference Sheet  V.1 | 2


© 2020 College Board
Instruction Explanation
Iteration
Text: The code in block of statements is executed n times.
REPEAT n TIMES
{
<block of statements>
}
Block:

REPEAT n TIMES

block of statements

Text: The code in block of statements is repeated until the


REPEAT UNTIL(condition) Boolean expression condition evaluates to true.
{
<block of statements>
}
Block:

REPEAT UNTIL condition

block of statements

List Operations
For all list operations, if a list index is less than 1 or greater than the length of the list, an error message is produced and the program
terminates.
Text: Creates a new list that contains the values value1, value2,
aList ← [value1, value2, value3, ...] value3, and ... at indices 1, 2, 3, and ...
respectively and assigns it to aList.
Block:

aList valuel, value2, value3

Text: Creates an empty list and assigns it to aList.


aList ← []
Block:

aList

Text: Assigns a copy of the list bList to the list aList.


aList ← bList
For example, if bList contains [20, 40, 60],
Block:
then aList will also contain [20, 40, 60] after the
aList bList assignment.

Text: Accesses the element of aList at index i. The first element


aList[i] of aList is at index 1 and is accessed using the notation
aList[1].
Block:

aList i

AP Computer Science Principles Exam Reference Sheet    | 3


 V.1 
© 2020 College Board
Instruction Explanation
List Operations (continued)
Text: Assigns the value of aList[i] to the variable x.
x ← aList[i]
Block:

x aList i

Text: Assigns the value of x to aList[i].


aList[i] ← x
Block:

aList i x

Text: Assigns the value of aList[j] to aList[i].


aList[i] ← aList[j]
Block:

aList i aList j

Text: Any values in aList at indices greater than or equal to i are


INSERT(aList, i, value) shifted one position to the right. The length of the list is increased by
1, and value is placed at index i in aList.
Block:

INSERT aList, i, value

Text: The length of aList is increased by 1, and value is placed at


APPEND(aList, value) the end of aList.
Block:

APPEND aList, value

Text: Removes the item at index i in aList and shifts to the left
REMOVE(aList, i) any values at indices greater than i. The length of aList is
decreased by 1.
Block:

REMOVE aList, i

Text: Evaluates to the number of elements in aList.


LENGTH(aList)
Block:
LENGTH aList

Text: The variable item is assigned the value of each element of


FOR EACH item IN aList aList sequentially, in order, from the first element to the last
{ element. The code in block of statements is executed
<block of statements> once for each assignment of item.
}

Block:

FOR EACH item IN aList

block of statements

AP Computer Science Principles Exam Reference Sheet    | 4


 V.1 
© 2020 College Board
Instruction Explanation
Procedures and Procedure Calls
Text: Defines procName as a procedure that takes zero or more
PROCEDURE procName(parameter1, arguments. The procedure contains block of statements.
parameter2, ...) The procedure procName can be called using the following
{ notation, where arg1 is assigned to parameter1, arg2 is
<block of statements> assigned to parameter2, etc.:
} procName(arg1, arg2, ...)
Block:

PROCEDURE procName parameter1,


parameter2,...

block of statements

Text: Defines procName as a procedure that takes zero or more


PROCEDURE procName(parameter1, arguments. The procedure contains block of statements
parameter2, ...) and returns the value of expression. The RETURN
{ statement may appear at any point inside the procedure and
<block of statements> causes an immediate return from the procedure back to the calling
RETURN(expression) statement.
} The value returned by the procedure procName can be assigned
to the variable result using the following notation:
Block:
result ← procName(arg1, arg2, ...)
PROCEDURE procName parameter1,
parameter2,...

block of statements
RETURN expression

Text: Returns the flow of control to the point where the procedure was
RETURN(expression) called and returns the value of expression.
Block:
RETURN expression

Robot
If the robot attempts to move to a square that is not open or is beyond the edge of the grid, the robot will stay in its current location
and the program will terminate.

Text: The robot moves one square forward in the direction it is facing.
MOVE_FORWARD()
Block:

MOVE_FORWARD

Text: The robot rotates in place 90 degrees counterclockwise (i.e., makes


ROTATE_LEFT() an in-place left turn).
Block:

ROTATE_LEFT

AP Computer Science Principles Exam Reference Sheet    | 5


 V.1 
© 2020 College Board
Instruction Explanation
Robot
Text: The robot rotates in place 90 degrees clockwise (i.e., makes an in-
ROTATE_RIGHT() place right turn).
Block:

ROTATE_RIGHT

Text: Evaluates to true if there is an open square one square in the


CAN_MOVE(direction) direction relative to where the robot is facing; otherwise evaluates to
Block: false. The value of direction can be left, right,
forward, or backward.
CAN_MOVE direction

AP Computer Science Principles Exam Reference Sheet    | 6


V.1 
© 2020 College Board

You might also like