perform actions for only some values of an increasing variables

Asked by JD

Hi,

I am trying to perform an action for some values only of an increasing variable. I want to perform this action for v<7 and 8<v<12 (excluding 7 and 8) and then increase the variable v by 1.
Something along the lines of :

v=0
while v<7 or 8<v<12:
    print "example action"
    v=v+1

How do i do this without the loop 'breaking' when v=7. I am not sure that a while loop is the right option here.
Thank you very much

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
JD
Solved:
Last query:
Last reply:
Revision history for this message
Roman Podolyan (podolyan-roman) said :
#1

What's the problem, really?

v=0
while v < 12 :
    if (v <> 7) and (v <> 8):
        print ("example action " + str(v))
    v=v+1

And you can put in inside "if" any condition you want to exclude

Revision history for this message
RaiMan (raimund-hocke) said :
#2

even shorter:

for v in range(1,7) + range(9,12):
    print "example action", v

Revision history for this message
JD (keelbo) said :
#3

Thank you guys for your help, just what i was looking for.