FOR LOOPS Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is a loop?

A

Loops are a useful control structure for repeating a block of code multiple times. There are several types of loops in most programming languages, but the most basic and commonly used is the for loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A for loop in Python has the following syntax:

A

for item in iterable:

Here, item is a variable that takes on each value in the iterable one at a time, and the indented code block following the for statement is executed once for each value. An iterable is a data type that can be iterated over, such as a list, a tuple, or a string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write out an example:

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly