Pro Tip: Spindle's syntax mirrors what you'll see on the AP CSP exam, helping you feel confident on test day.
Programming Guide
data_object Variables
Varibles can be assigned a value using "<--" OR "<-" For example, the following code sets a to 10 and then to 13 (a's value plus 3).
a <- 10
a <-- [1,2,3]
Varibles can be assigned to other varibles!
b <-- a / 2
If you added this line to the lines above, it would set b to a's value divided by 2, resulting in 6.5
code Logical Operators
NOT
Negates the condition
AND
Returns TRUE if both conditions are TRUE
OR
Returns TRUE if at least one condition is TRUE
🆚 Comparison Operators:
In this language:
0 is FALSE
1 is TRUE
The supported comparison operators are:
- < 4. >=
- <= 5. ==
- > 6. !=
❔ If Statements:
If Statements can be defined with the keyword IF, and then the expression that must be true. The code that is to be ran when the the condition is met must be wrapred in brackets. If the condition for the IF statement is false, you can write an ELSE statement that will be ran instead
a <-- 5
IF a==5 {
RETURN 1
} ELSE {
RETURN 0
}
loop Loops
For Loops (REPEAT TIMES)
For Loops are defined by the keyword REPEAT, followed by the number of times you want it to repeat, the keyword TIMES, and finally the code you want to be repeated.
a <-- 5
REPEAT 10 TIMES {
a <-- a + 1
}
DISPLAY(a) # Output: 15
While Loops (REPEAT UNTIL)
While loops use REPEAT UNTIL, followed by a condition in parentheses, and the code block in curly braces. The loop continues until the condition becomes true.
a <-- 10
REPEAT UNTIL (a > 30) {
a <-- a + 4
} # Final value: 34
function Functions
Procedures (Functions)
Functions are defined using the keyword 'PROCEDURE', followed by the function name and arguments in parentheses, with the code block in curly braces.
PROCEDURE SAY_HI(excitement) {
REPEAT excitement TIMES {
DISPLAY("Hi!")
}
}
SAY_HI(3) # Outputs: Hi! Hi! Hi!
Built-in Functions
DISPLAY(value)
: Display output to the consoleINPUT()
: Gets user inputCLEAR()
: Clears the consoleIS_NUM(value)
: Returns 1 if value is a number, 0 otherwiseIS_STR(value)
: Returns 1 if value is a string, 0 otherwiseIS_LIST(value)
: Returns 1 if value is a list, 0 otherwiseLENGTH(list)
: Returns the length of a list (starts at 1 per College Board)