Idea 2of 23Builds onCode is exact steps in order
Swap two lines, change the output
Does the order of the lines change what code gives back?
Today you'll discover
- how to run two programs side by side
- why the order matters
- when a swap changes the answer
Think firstCode A and code B use the same two lines
For the input 4, code A outputs 14. What does code B output?
Decide first, then press Next. Read code B from its own top line.
Two short programs side by side. Code A: ADD 3, MULTIPLY BY 2, OUTPUT. Code B: MULTIPLY BY 2, ADD 3, OUTPUT, with both changed lines framed. A table under them: input 4 gives 14 from A and 11 from B; input 10 gives 26 from A and 23 from B, each marked changed. The last step asks about SUBTRACT 2 and MULTIPLY BY 5, swapped.
See the whole ideathe big idea and the key word, in one place
The big idea
Code runs in sequence, so the same lines in a new order can give a new output.
Compare themADD 3 then MULTIPLY BY 2 turns 4 into 14. MULTIPLY BY 2 then ADD 3 turns 4 into 11.
Like a two-step ruleTwo-step pattern rules work the same way: multiply by 2 then add 3 is a different rule from add 3 then multiply by 2.
Key word
- sequence
- the order lines of code run in: one after another, from the top down
Ready to use it?
- Say what a program outputs after two of its lines are swapped.