I’m making a program and I need to loop through a string, but all I’ve really seen for loops in the manual and through forums are while loops. I was wondering if there is a for loop, so I can loop through each letter of the string and do something based off each letter.
There is no “for do” loop.
Something like this should work as a work around.
(untested, could have syntax errors)
#zero the loop counter
i=0;
#define your string
myString := “hello”;
#begin loop
while (i < str_len(myString)): #loop from 0 to 4
thisLetter := str_at(myString, i) #get byte at index i
#do whatever based on the letter
if thisLetter = “h”:
popup(“letter is h”)
elif thisLetter = “e”:
popup("letter is e)
else:
popup(“letter is neither h nor e”)
end
#increment loop counter
i := i + 1
#end loop
end
Thank you. This shows me that I was on the right track. I figured I would have to get the length of the string and loop through it while some other var was lower. This helped a lot thx.