How to get a command to repeat about 10 times

Asked by arminius

"click("460450485686722.png")
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()
        click()"

What's an easy way to just click() * 10
I tried the above command, it just clicked once.

Mint 18.1 KDE

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

Standard Python syntax
https://wiki.python.org/moin/ForLoop

for n in range(0, 10):
        click()

Revision history for this message
Mauro Edmundo Vargas Veloz (edmundo-01) said :
#2

count = 1
while (count < 10):
 click("460450485686722.png")
 count = count + 1
print ("finish")

Revision history for this message
arminius (arminius75) said :
#3

"count = 1
        while (count < 10):
        click(Pattern("58679475550934.png").targetOffset(-8,-8))
        count = count + 1"

returns "[error] SyntaxError ( "mismatched input 'click' expecting INDENT", )"

Revision history for this message
arminius (arminius75) said :
#4

"for n in range(0, 10):
        click()"

returns "[error] SyntaxError ( "mismatched input 'click' expecting INDENT", )"

Revision history for this message
Best Manfred Hampl (m-hampl) said :
#5

You seem to have misformatted the input.
Whitespace is significant in Python.
Python groups statements according to the amount of whitespace in front of it.

"count = 1
         while (count < 10):
         click(Pattern("58679475550934.png").targetOffset(-8,-8))
         count = count + 1"
is wrong, it probably has to be
"count = 1
while (count < 10):
         click(Pattern("58679475550934.png").targetOffset(-8,-8))
         count = count + 1"
denoting that the indented lines (click... and count=count+1) are inside the while loop.

Please check with python manuals.

Revision history for this message
arminius (arminius75) said :
#6

"count = 1
while (count < 10):
         click(Pattern("58679475550934.png").targetOffset(-8,-8))
         count = count + 1"

returned [error] SyntaxError ( "mismatched input ')' expecting NEWLINE", )

Revision history for this message
Manfred Hampl (m-hampl) said :
#7

It seems that you have an extra closing bracket somewhere.
Are you sure that the error is caused by one of the lines in your snippet and not by some other part of your code?

Revision history for this message
arminius (arminius75) said :
#8

Thanks Manfred Hampl, that solved my question.