How to jump in a for loop Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
rodemp
Posts: 43
Joined: 15 Nov 2016, 00:28

How to jump in a for loop

02 Aug 2018, 03:25

I want to know how to jump back to a specific point in the middle of listing the Data Obj as a for loop

Data := [["a",10], ["b",20], ["c",30], ["d",40]]


for k, n in Data
msgbox % "name - " n[1] " / value" n[2]

if (k=4) && (n[2]>30)
n[2]-=10 and Emulate start to k=2

I want msgbox to look like this

msgbox name - a / value 10
msgbox name - b / value 20
msgbox name - c / value 30
msgbox name - d / value 40

msgbox name - b / value 20
msgbox name - c / value 30
msgbox name - d / value 30

how to do
User avatar
TLM
Posts: 1418
Joined: 01 Oct 2013, 07:52
GitHub: TLMcode
Contact:

Re: How to jump in a for loop  Topic is solved

02 Aug 2018, 14:06

Straight forward approach:

Code: Select all

Data := [["a",10], ["b",20], ["c",30], ["d",40]]

Loop % Data.Length()-2
{
	Count := A_Index
	for k, n in Data
	{
		if ( k >= Count ) 
		msgbox % "name - " n[1] " / value" n[2]	"`n"
	}
}
for direct help, tweet at me: https://twitter.com/CW_DTech
swagfag
Posts: 2602
Joined: 11 Jan 2017, 17:59

Re: How to jump in a for loop

02 Aug 2018, 15:35

Code: Select all

Data := [["a",10], ["b",20], ["c",30], ["d",40]]

result := print(Data)

if ((last := Data[Data.Length()])[2] > 30)
	last[2] -= 10

first := Data.RemoveAt(1)

result .= "`n" print(Data)

Data.InsertAt(1, first)

MsgBox % result

print(Data) {
	for k, n in Data
		str .= "name - " n[1] " / value" n[2] "`n"

	return str 
}
rodemp
Posts: 43
Joined: 15 Nov 2016, 00:28

Re: How to jump in a for loop

03 Aug 2018, 01:50

oh i use normal loop but thank you for your reply.

Code: Select all

Data := [["a",10], ["b",20], ["c",30], ["d",40]]
k:=1
Loop {
	MsgBox % "name -" Data[k,1] " / " Data[k,2]
	if (k=4) && (Data[k,2]>30)
		Data[k,2]-=10, k:=1
	if (k >= Data.MaxIndex())
		break
	k++
}

Return to “Ask For Help”

Who is online

Users browsing this forum: andrewvanmarle, Bing [Bot], bschamel, swagfag and 153 guests