Iterating Over String
How does one interate over a string...
For example, in python you might do:
How might I do this in SPIN?
Thanks,
John
For example, in python you might do:
s = "String"
for x in s:
print x
How might I do this in SPIN?
Thanks,
John

Comments
There's no string type in Spin, but you can define a string as an array of bytes in a DAT block.
dat MyStr byte "string", 0 pub main | p, c p := @MyStr repeat c := byte[p++] if (c > 0) print(c) else quitBut as he said there is no string type, it's just an array of bytes, the string() function just creates this array in-line, but it functions the same as declaring a string in DAT, except it automatically terminates the string with a 0-byte and returns the address of the string.
An alternative:
p := string("string") REPEAT strsize(strAddr) ' for each character in string print(byte[p++]) ' write the characterBut then you'll have to reset p every time you do that. It would be better in a method like this:
PUB Main print_str(string("string")) PRI print_str (strAddr) REPEAT strsize(strAddr) ' for each character in string print(byte[strAddr++]) ' write the characterBasically this is for slowly printing a string, so printing a string to the TV one character at a time, to get that kind of "Typewriter" feel...
Anyway, thanks for the help!
-John