titer.nim 1.0 KB

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