Can you identify branching in an algorithm?
Follow this rounding algorithm for the number 9.7:
If the digit after the decimal point is 5 or more than 5, round up to the next whole number.
If the digit after the decimal point is less than 5, write the number without the decimal value.
The key word to look for with a branch is if.
This video shows us what a loop (or iteration) is, and why they are used in code.
Nadia follows an algorithm to eat her breakfast.
Place bowl and spoon on the table
Pour cereal into the bowl
Pour milk into the bowl
Spoon a mouth of cereal into your mouth
Repeat step 4 until the cereal is finished
Place bowl and spoon in the sink
Does this algorithm contain a loop?
Which two steps form the loop?
Follow the algorithm below to fill in the results.
Step | Instruction | Result |
---|---|---|
1 | \text{Start with the number $29$} | ⬚ |
2 | \text{Subtract $1$ from this number} | ⬚ |
3 | \text{Repeat step $2$ three more times} | ⬚\\⬚\\⬚ |
4 | \text{Double the number} | ⬚ |
Iteration means to repeat steps in an algorithm.