Python Forum

Full Version: for loop question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I am trying to find the correct syntax to use in a for loop using an expression as a test condition.
The pseudo code i am trying to convert is.

Set MyNumber = 7
For (Count = 1; Count <= (MyNumber + 1); Count+3)
Write Count
End For


Thank you for any help.
mynumber = 7
for counter in range(1, mynumber+2,3) :
    print(counter)
The key is the range function. It yields a series of number from the first item to the second item exclusive, stepping by the 3rd item.