Jump to content
Sign in to follow this  
neltisen

how to loop for exact amount times?

Recommended Posts

neltisen

Hello,

I was using AutoIt (I think it was AutoIt, but I'm not sure) around half year ago. For few months I forgot about its (even name, I had full disc format, so I'm not sure if it was this app :P). Through this time I have completly forgotten my scripts, but I remember something like this:

$id = 1

loop 1000

send ( "add skill" $id)

sleep 200

$id += 1

(this macro was usable to learn all abilities in HoMM V ;) )

I know that I can use For...until in exchange, but what when I don't need var in my script?

example:

loop 20

send ( "wtb g40 stuff" )

sleep 1000

how to use loop here only for (as example) 20 times?

Share this post


Link to post
Share on other sites
FireLord

you could do like this:

$i=0

Do

; code

$i = $i+1

Until $i = 20

It would increment I until it equals 20 so you would keep looping 20 times


[center]See the Helpfile[/center]
While Alive()
	 DrinkWine();
}
[center][/center]

Share this post


Link to post
Share on other sites
weaponx

For $X = 1 to 20

Next

Share this post


Link to post
Share on other sites
John117

I perfer the method weaponx listed. -It just seems cleaner/ easier. When I am in question, I just adapt these from VBA

CODE
Sub Main()

DoLoop

WhileWend

ForNext

ForEach

SpecialCells

EndDown

End Sub

Private Sub DoLoop()

Dim r As Range

Set r = Range("a1")

Do Until IsEmpty® Or r.Row = Rows.Count

Set r = r.Offset(1)

Loop

End Sub

Private Sub WhileWend()

Dim r As Range

Set r = Range("a1")

While Not IsEmpty® And r.Row <> Rows.Count

Set r = r.Offset(1)

Wend

End Sub

Private Sub ForNext()

For i = 1 To Application.WorksheetFunction.CountA(Range("A:A"))

If IsEmpty(Cells(i, 1)) Then Exit For

Next i

End Sub

Private Sub ForEach()

Dim r As Range

For Each r In Range("A:A").Cells

If IsEmpty® Then Exit For

Next r

End Sub

Private Sub SpecialCells()

Set r = Range("A:A").SpecialCells(xlCellTypeBlanks)

End Sub

Private Sub EndDown()

Dim r As Range

Set r = Range("a1")

Select Case True

Case IsEmpty®

' do nothing

Case IsEmpty(r.Offset(1))

Set r = r.Offset(1)

Case Else

Set r = r.End(xlDown).Offset(1)

End Select

End Sub

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×