Hi,
The c language has something like “for(0,<a.cont,1)” or you if you want you can write “for(0, a.cont-1,1)” so this is clearer (I never thought I ever in my life would use an C example to show that something is clearer!
).
In Cobra, the implicit <a.count is OK when counting up:
- Code: Select all
fileNames = ["a.xls", "b.ppt", "c.ppt", "a.doc"]
for i in 0 : fileNames.count # OK
print i, fileNames[i]
But see what it looks like when counting down:
- Code: Select all
for i in fileNames.count-1: 0-1 :-1
print i, fileNames[i]
In my opinion, this looks terrible and is error prone. To avoid this, Cobra could have an iterator that is guaranteed in order (have no better wording for this right now). Iterating up is not really needed, see above (except for symmetry reason), but for iterating down, it would be nice to avoid the example above:
- Code: Select all
forup i, fileName in fileNames
print i, fileName
fordown i, fileName in fileNames
print i, fileName
Or does it already exist? (I think I have somewhere read a discussion about in-order iterators). Or are there better ways already? Anyhow, the count down example in an array has to be documented for newbies to Cobra.
Regards
Csaba