Page 1 of 1
for Loop on characters.
Posted: Tue Dec 18, 2007 8:31 am
by bembulak
Sometimes I think something like this would come very handy:
Code: Select all
For i.s = "a" To "z"
; do anything
Next
For j.s = "A" To "Z"
; do something other
Next
This would enhance some string operations, I think. Seen it sometimes in other languages (ObjectPascal and Python, eg) and it's neat.
Posted: Tue Dec 18, 2007 8:41 am
by remi_meier
I don't understand what you're doing.
Do you want something like that:
Code: Select all
Structure chars
c.c[0]
EndStructure
s.s = "hallo"
len.l = Len(s)
*p.chars = @s
For z = 0 To len - 1
Debug Chr(*p\c[z])
Next
Your syntax proposal isn't clear to me..
Or do you want something like this:
Code: Select all
For z = 'a' To 'z'
Debug Chr(z)
Next
Posted: Tue Dec 18, 2007 10:30 am
by bembulak
Or do you want something like this:
Code:
For z = 'a' To 'z'
Debug Chr(z)
Next
Yeah, that one.
Just the way ObjectPascal and Python do it.
Posted: Tue Dec 18, 2007 2:58 pm
by Trond
bembulak wrote:Or do you want something like this:
Code:
Code: Select all
For z = 'a' To 'z'
Debug Chr(z)
Next
Yeah, that one.
Just the way ObjectPascal and Python do it.
Did you try to run that code?
Posted: Tue Dec 18, 2007 3:07 pm
by Dare
Trond wrote:Did you try to run that code?
Okay, you got me curious. It looks okay and it works here. Produces "a" through to "z".
What have you spotted?
Posted: Tue Dec 18, 2007 3:10 pm
by Trond
Just that he requests something that is implemented, and probably didn't notice.
Posted: Tue Dec 18, 2007 3:20 pm
by traumatic
just like christmas...
Posted: Tue Dec 18, 2007 3:27 pm
by Dare
traumatic wrote:just like christmas...
Trond wrote:Just that he requests something that is implemented, and probably didn't notice.
Ah, I see. I just thought maybe you had unearthed something unexpected.
Mind you the requested looping option was all strings: For i.s = "A" to "Z" so I guess there was a difference.
I'm not sweating on whether this one is implemented.

Posted: Tue Dec 18, 2007 4:44 pm
by Trond
The topic title said characters.
Posted: Tue Dec 18, 2007 7:28 pm
by Mistrel
I didn't know you could do that!
In the past I've done something like this:
Code: Select all
#LCase=abcdefghijklmnopqrstuvwxyz
#UCase=ABCDEFGHIJKLMNOPQRSTUVWXYZ
For i=1 To Len(#LCase)
If somevar.s=Mid(#LCase,i,1)
; do something
Break
EndIf
Next i
Posted: Tue Jan 15, 2008 10:57 pm
by bembulak
I didn't know you could do that!
I didn't too!
I really did not now, that
will work, since you're passing 'a', .. on to the variable z, which is an integer value.
The code I tried to do, was for
i.s = 'a'...
What a bad mistake.
Shame on me...
