Grok Worksheet 8: Iteration Flashcards
1
Q
What are four advantages of using iteration over manually entering repeated code? Or disadvantages of using repeated code?
A
- Without iteration there would be way more lines of code
- Without iteration coding is more tedious
- Without iteration coding is more error-prone
- Manual coding without iteration does not scale
- With iteration if the code changes then you need to make far fewer changes to the code.
2
Q
Describe the *= operator.
A
c *= 2 is the same as c = c * 2
3
Q
Describe the /= operator.
A
c /= 2 is the same as c = c / 2
4
Q
Describe the += operator.
A
c += 2 is the same as c = c + 2
5
Q
Describe the -= operator.
A
c -= 2 is the same as c = c - 2
6
Q
Describe the //= operator.
A
c //= 2 is the same as c = c // 2
7
Q
Describe the %= operator.
A
c %= 2 is the same as c = c % 2
8
Q
Describe the **= operator.
A
c = 2 is the same as c = c2