1 2 3 4 5 6 7 8 9 10 11 12 13
Revise later
SpaceTo flip
If confident
All Flashcards
What is the purpose of a 'repeat n times' loop?
To execute a block of code a specific number of times.
What is the Python equivalent of 'REPEAT n TIMES'?
The `for...in range()` loop.
Why are loops important in programming?
They allow us to automate repetitive tasks and write more efficient code.
Explain the concept of a loop counter.
A variable that keeps track of the number of times a loop has executed.
What is the range() function in Python?
A built-in function that creates a sequence of numbers, often used in for loops.
What is the purpose of the 'n' in 'REPEAT n TIMES'?
It specifies the number of times the loop will iterate.
What is iteration?
Repeating a block of code multiple times.
What is a loop?
A programming construct that repeats a sequence of instructions until a specific condition is met.
What is pseudocode?
An informal way of describing an algorithm or program using a mix of natural language and programming constructs.
What does the following code output?
```python
for x in range(3):
print(x)
```
0
1
2
What does the following code output?
```python
for i in range(1, 5):
print(i)
```
1
2
3
4
What does the following code output?
```python
for i in range(2, 10, 2):
print(i)
```
2
4
6
8
What does the following code output?
```python
n = 0
for i in range(5):
n = n + 1
print(n)
```
5