Osamah Ahmad Osamah Ahmad - 8 months ago 39
Python Question

How do I represent this FOR loop in Python?

How do I represent this structured English 'code' in Python code?

Structured English:

FOR NoOfGamesPlayed <-- 1 TO NoOfGamesInMatch Do

I can do it in VB.NET:

For NoOfGamesPlayed = 1 To NoOfGamesInMatch

I'm confused on how to do it in Python.

for NoOfGamesPlayed in range(1, NoOfGamesInMatch+1):
    # do stuff

But note that Python uses 0-based indexing, not 1-based indexing.

So for a list of 5 elements, the valid indices are [0] through [4].