Osamah Ahmad Osamah Ahmad - 1 year ago 94
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.

Answer Source
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].

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download