tloops.nim 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. discard """
  2. output: '''
  3. Hello!(x: 1, y: 2, z: 3)
  4. (x: 1.0, y: 2.0)
  5. '''
  6. """
  7. # Test nested loops and some other things
  8. proc andTest() =
  9. var a = 0 == 5 and 6 == 6
  10. proc incx(x: var int) = # is built-in proc
  11. x = x + 1
  12. proc decx(x: var int) =
  13. x = x - 1
  14. proc First(y: var int) =
  15. var x: int
  16. i_ncx(x)
  17. if x == 10:
  18. y = 0
  19. else:
  20. if x == 0:
  21. incx(x)
  22. else:
  23. x=11
  24. proc TestLoops() =
  25. var i, j: int
  26. while i >= 0:
  27. if i mod 3 == 0:
  28. break
  29. i = i + 1
  30. while j == 13:
  31. j = 13
  32. break
  33. break
  34. while true:
  35. break
  36. proc Foo(n: int): int =
  37. var
  38. a, old: int
  39. b, c: bool
  40. F_irst(a)
  41. if a == 10:
  42. a = 30
  43. elif a == 11:
  44. a = 22
  45. elif a == 12:
  46. a = 23
  47. elif b:
  48. old = 12
  49. else:
  50. a = 40
  51. #
  52. b = false or 2 == 0 and 3 == 9
  53. a = 0 + 3 * 5 + 6 + 7 + +8 # 36
  54. while b:
  55. a = a + 3
  56. a = a + 5
  57. write(stdout, "Hello!")
  58. # We should come till here :-)
  59. discard Foo(345)
  60. # test the new type symbol lookup feature:
  61. type
  62. MyType[T] = tuple[
  63. x, y, z: T]
  64. MyType2 = tuple[x, y: float]
  65. proc main[T]() =
  66. var myType: MyType[T]
  67. var b: MyType[T]
  68. b = (1, 2, 3)
  69. myType = b
  70. echo myType
  71. var myType2: MyType2
  72. var c: MyType2
  73. c = (1.0, 2.0)
  74. myType2 = c
  75. echo myType2
  76. main[int]()