



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
AP Computer Science Principles Exam Reference Sheet includes Selection, Iteration, List Operations, Procedures
Typology: Cheat Sheet
1 / 6
This page cannot be seen from the preview
Don't miss anything!
®
Assignment, Display, and Input Text: a ← expression
Block:
Evaluates expression and assigns the result to the variable a.
Text: DISPLAY (expression)
Block:
Displays the value of expression, followed by a space.
Text: INPUT ()
Block:
Accepts a value from the user and returns it.
Arithmetic Operators and Numeric Procedures Text and Block: a + b a - b a * b a / b
The arithmetic operators +, - , *, and / are used to perform arithmetic on a and b.
For example, 3 / 2 evaluates to 1.5.
Text and Block: a MOD b
Evaluates to the remainder when a is divided by b. Assume that a and b are positive integers.
For example, 17 MOD 5 evaluates to 2. Text: RANDOM (a, b)
Block:
Evaluates to a random integer from a to b, including a and b.
For example, RANDOM (1, 3) could evaluate to 1 , 2 , or 3. Relational and Boolean Operators Text and Block: a = b a π b a > b a < b a b a b
The relational operators =, π , >, <, , and are used to test the relationship between two variables, expressions, or values.
For example, a = b evaluates to true if a and b are equal; otherwise it evaluates to false.
Text: NOT condition
Block:
Evaluates to true if condition is false; otherwise evaluates to false.
Text: condition1 AND condition
Evaluates to true if both condition1 and condition2 are true; otherwise evaluates to false.
Iteration (continued) Text: REPEAT UNTIL (condition) {
Block:
The code in block of statements is repeated until the Boolean expression condition evaluates to true.
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: list[i]
Block:
Refers to the element of list at index i. The first element of list is at index 1.
Text: list[i] ← list[j]
Block:
Assigns the value of list[j] to list[i].
Text: list ← [value1, value2, value3]
Block:
Assigns value1, value2, and value3 to list[1], list[2], and list[3], respectively.
Text: FOR EACH item IN list {
The variable item is assigned the value of each element of list sequentially, in order from the first element to the last element. The code in block of statements is executed once for each assignment of item.
List Operations (continued) Text: INSERT (list, i, value)
Block:
Any values in list at indices greater than or equal to i are shifted to the right. The length of list is increased by 1, and value is placed at index i in list.
Text: APPEND (list, value)
Block:
The length of list is increased by 1, and value is placed at the end of list.
Text: REMOVE (list, i)
Block:
Removes the item at index i in list and shifts to the left any values at indices greater than i. The length of list is decreased by 1.
Text: LENGTH (list)
Block:
Evaluates to the number of elements in list.
Procedures Text: PROCEDURE name (parameter1, parameter2, ...) {
Block:
A procedure, name, takes zero or more parameters. The procedure contains programming instructions.
Text: PROCEDURE name (parameter1, parameter2, ...) {
A procedure, name, takes zero or more parameters. The procedure contains programming instructions and returns the value of expression. The RETURN statement may appear at any point inside the procedure and causes an immediate return from the procedure back to the calling program.