Welcome to ✨ Spindle's User Documentation ✨

The language used in the AP CSP Exam, now a programming language!

Programming Guide

✖️ Variables:

Variables are like containers that hold information. This information can be anything, like numbers, words, or even more complex data structures. The key thing about variables is that their contents can change throughout a program's execution. This allows us to write flexible code that can adapt to different situations and inputs.

How would you swap the values of two variables?
a <-- 10
b <-- 10
c <--  a
a <-- b
b <-- c
play_arrow # See it for yourself!

1. a <- 10
2.
3. b <-- a / 2

💡 Logical Operators:

NOT: Negates the condition
AND: Returns TRUE if and only if BOTH conditions are TRUE
OR: Returns TRUE if at least one of the conditions are true

🆚 Comparison Operators:

In this language:
0 is FALSE
1 is TRUE
The supported comparison operators are:

  1. <       4. >=
  2. <=    5. ==
  3. >       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
}

🔄 For Loops

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)

In the example above, a would now have the value of 15

🔁 While Loops

While loops are defined by the keywords REPEAT UNTIL, then the condition [surrounded by ()], and then the code you want repeated [surrounded by {}] Like the code reads, the loop will run until the condition is true. You can think it as a while loop running while (NOT condition)

a <-- 10
REPEAT UNTIL (a > 30) { a <-- a + 4}

In the example above, a would now have the value of 34

🔁 Functions

Functions are defined by the keyword 'PROCEDURE', then the function name and or arguments [surrounded by ()], and then the code you want in the function body [surrounded by {}]

PROCEDURE SAY_HI(excitement) {
    REPEAT excitement TIMES {
        DISPLAY("Hi!")
    }
}

*The DISPLAY() function is an built-in function, meaning it doesn't have to be defined. Other built-in functions are: INPUT(): Gets user input CLEAR(): Clears the console IS_NUM(something): Returns True (1) if something is a number and False (0) otherwise IS_STR(something): Returns True (1) if something is a string and False (0) otherwise IS_LIST(something): Returns True (1) if something is a list and False (0) otherwise LENGTH(list): Returns the length of a list. As per college board guidelines, starts counting at 1 RUN(filename): Runs a spindle file at a specific filename. You shouldn't use this directly in your programs

📖 Resources

The AP Computer Science Exam Reference Sheet can be found here: https://apcentral.collegeboard.org/media/pdf/ap-computer-science-principles-exam-reference-sheet.pdf

Written with the help of a tutorial by CodePulse, which can be found here: https://youtu.be/Eythq9848Fg?si=yDuSPkEzG2y1X1cm