repeat while image not found only a few times

What am I doin’ wrong here? I want this repeat to only run 10 times then go onto other stuff OUTSIDE the repeat… but just keeps going.



repeat while not imageFound (5.0, "viewaccounts") 
	RightClick ""
	Wait 1.0
	if repeatIndex() equals 10 then 
		Wait 0.1
	end if
End repeat


Instead of setting the Wait to .1, you need to call

exit repeat

I just want to exit the REPEAT… somehow I got the code below. Is that going to kill the whole run? The “Exit All” bit?

	repeat while not imageFound ( 0.1, "paybillbuttonready")
		TypeText downArrow
		if repeatIndex() equals 100 then exit all 
	end repeat 

Yes, it will kill the whole run, but there is also an “exit repeat”. You can also write this loop as:

repeat while not imageFound ( 0.1, "paybillbuttonready") and repeatIndex() < 100
      TypeText downArrow
 end repeat

So I could do this:


 repeat while not imageFound ( 0.1, "paybillbuttonready") 
      TypeText downArrow 
      if repeatIndex() equals 100 then exit repeat 
   end repeat 

Or this:


repeat while not imageFound ( 0.1, "paybillbuttonready")  and repeatIndex() < 100      
TypeText downArrow 
   end repeat 

Yes. Technically the version with “repeatIndex() < 100” repeats one fewer times, so you could change it to “<>” or “is not equal to” if this specific example matters.

Actually, I do have some of these which work properly. Which colors up fine. You do have to put “exit repeat” on it’s own line…


repeat while not imageFound (3.0, "manageapps") 
	TypeText PageUp -- Settings
	Wait 2.0
	if repeatIndex() equals 3 then 
		exit repeat
	end if
End repeat

I feel I need to clarify this: There is no need to put the exit repeat on its own line. The code:

	if repeatIndex() equals 3 then exit repeat

is functionally equivalent to, and should work the same as:

if repeatIndex() equals 3 then
      exit repeat
end if 

Interesting…


// Works
repeat while not imageFound(0.5, "messaging") and repeatIndex() < 3
	Put woohoo
End repeat


// Works
repeat while not imageFound (0.5, "Messaging")
	Put woohoo
	if repeatIndex() equals 3 then 
		exit repeat
	end if
End repeat


// Works
repeat while not imageFound (0.5, "Messaging")
	Put woohoo
	if repeatIndex() equals 3 then exit repeat
End repeat


// Syntax Error -- I didn't need the End If apparently.
repeat while not imageFound (0.5, "Messaging")
	Put woohoo
	if repeatIndex() equals 3 then exit repeat
End if
End repeat

Right. The single-line “if” statement isn’t a block and doesn’t require a closing “end if”.