Interactive · 1 question

Code

Code will be written by numbering each line. Many special tags will be written in bold and caps lock, including but not limited to: TRUE, FALSE, IF, ELSE IF, ELSE, FOR, IN, WHILE, FUNCTION, RETURN, etc. Indentation is also very critical to how to read code, as you will see later. Code comments will be written using //.

Variables

Just as in math, we can make variables and give them values. We denote ←\gets to denote the assignment of a value to a variable. For example:

1: x←5x\gets5

creates a variable called xx and assigns to it the value 55.

Variables (as implied by the word variable) can change their values. For example:

1: x←5x\gets5

2: x←x+6x\gets x+6

Each time a ←\gets is called, we compute the expression on the right of the ←\gets, then assign that value to the variable on the left. Therefore, x=5x=5 after line 1 runs, then x+6=5+6=11x+6=5+6=11 computed, and then it is assigned to it. So x=11x=11 after line 2 runs.

What is the value of zz after the following code runs:

1: x←7x\gets7

2: y←8y\gets8

3: x←2⋅xx\gets2\cdot x

4: z←x−yz\gets x-y

Choose one answer

Type a concept, like “slope” or “photosynthesis”.

↑ ↓ to choose · Enter to openSearch explanations and problems