Is this sentence correct?

The indented code in the body gets executed the same number of times as the number of elements in the iterable variable

What does The indented code refer to?
What does the iterable variable refer to and how many elements are there in it?

Without the above 2 pieces of information, there is no way to assess the statement just from reading this question alone.

You can share why you think this statement is possibly wrong.
Eg. Is it because the indented code should get executed more/less than …?
Or is it because the indented code should get executed the same number of times as something else?

Then others will be able to identify and explain why some assumptions you have may be wrong, or confirm them to be right.

1 Like

This rule is written in the first of the ’ for loops ’ section.

I wish to help but it’s impossible given the little information I have.
Imagine someone coming to this page, and the only thing they see is a sentence, with no direct clickable link to where it came from, or what exactly is the confusion about.


Here is a nice article on how to help others help you.

If you could include a link to the source of the issue, that will help save others time and effort in getting context on your question.

However, even with the link provided, I would still need to understand why exactly do you think that statement is incorrect?
How would you have written it?

If you look at many open source libraries issue tracking and bug reporting pages on github, you will see they require two items for any discussion.

  1. Actual Code/Results
  2. Expected Code/Results

We need these two to form the basis of any comparison. Same for writing tests for code. If there is nothing expected, then there is nothing to compare against, and we can’t make any comments on the actual.

Analogy i’m trying to draw here is the provided statement is by itself, just a statement. You must have felt something is wrong with it, thus your question, so please clarify what do you expect the statement to look like?

1 Like

I am very sorry about this.
I am going to clarify here: I have read this sentence ( The indented code in the body gets executed the same number of times as the number of elements in the iterable variable ) while I am studying and I have asked if this sentence is always right.
I hope I could express my question.

Hi @Maho,

This sentence seems to be related to the explanation of the for-loops. In this context yes, it’s always right.

You have an iterable variable with several items. For example, a list called my_list. And you want to apply the same operation (or several operations) to each item of that list. So you create a for-loop, in the first line of which you write:

for item in my_list:

Then you write the indented block of your for-loop, representing the exact operations to be applied to each item of the list. And this indented block of the for-loop body gets executed the same number of times as the number of elements in the iterable variable (i.e. as the number of the items in your list, since they are applied to each item).

1 Like

Thanks a lot for clarification.

1 Like