Probably one to file under "Newbie Questions", but here goes...
I'm trying to iterate over a string and get the characters in it 3 at a time.
In Python, I can use the fact that range has a step attribute to do something like:
text = "Hello there How are you This is a string Blah Blah Blah"
for i in range(0, len(text)-2, 2):
print(text[i],text[i+1],text[i+2])
But I can't seem to find a similar way to do it in Nim. I've searched the docs but can't find any mention of how to define a step value when looping over <something>
Can someone give me a clue?
There is countup, which can be used as:
var text = "Hello there How are you This is a string Blah Blah Blah"
for i in countup(0, len(text)-3, 2):
echo text[i],text[i+1],text[i+2]
(Notice len(text)-3, because unlike Python's range, Nim's countup has inclusive bounds (You could also use high(text)-2)
Thanks. I just came back to red-facedly say I'd sussed it out. But you beat me to it.
I shall award myself the "RTFM Badge of Shame" immediately
[although, in my defence, I searched the docs for "range" and "step". Didn't think of "countup"]
I think it would be good to have a more fleshed out "Nim for {programming language} programmers". There are some of them on the github page
I would happily contribute to something line that
These are in our wiki and everybody can edit and improve them. Please do :)
but I haven't found any links to them
So you haven't read our page with the most learning resources yet? ;) https://nim-lang.org/learn.html
So you haven't yet read our page with the most learning resources? ;) https://nim-lang.org/learn.html
Apparently not 🤦♀️😅 can't remember when I looked there last time tbh. Are some really neat resources there!
These are in our wiki and everybody can edit and improve them. Please do :)
Will do ;)