titer.nim 810 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Test the new iterators
  2. iterator xrange(fromm, to: int, step = 1): int =
  3. var a = fromm
  4. while a <= to:
  5. yield a
  6. inc(a, step)
  7. iterator interval[T](a, b: T): T =
  8. var x = a
  9. while x <= b:
  10. yield x
  11. inc(x)
  12. #
  13. #iterator lines(filename: string): (line: string) =
  14. # var
  15. # f: tTextfile
  16. # shouldClose = open(f, filename)
  17. # if shouldClose:
  18. # setSpace(line, 256)
  19. # while readTextLine(f, line):
  20. # yield line
  21. # finally:
  22. # if shouldClose: close(f)
  23. #
  24. for i in xrange(0, 5):
  25. for k in xrange(1, 7):
  26. write(stdout, "test")
  27. for j in interval(45, 45):
  28. write(stdout, "test2!")
  29. write(stdout, "test3?")
  30. for x in items(["hi", "what's", "your", "name"]):
  31. echo(x)
  32. const
  33. stringArray = ["hi", "what's", "your", "name"]
  34. for i in 0..len(stringArray)-1:
  35. echo(stringArray[i])