PifyZ

Untitled

Feb 17th, 2015
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.89 KB | None | 0 0
  1. ###
  2. ----------------------
  3. Structures de contrôle
  4. ----------------------
  5. ###
  6. ### if seul ###
  7. if cond
  8.     ...
  9.  
  10. ### if avec else ###
  11. if cond
  12.     ...
  13. else
  14.     ...
  15.  
  16. ### if avec else if et else ###
  17. if cond
  18.     ...
  19. else if cond
  20.     ...
  21. else
  22.     ...
  23.  
  24. ### while ###
  25. while cond
  26.     ...
  27.  
  28. ### do-while ###
  29. do
  30.     ...
  31. while cond
  32.  
  33. ### loop seul ###
  34. loop
  35.     ...
  36.  
  37. ### loop itératif ###
  38. loop i
  39.     ...
  40.  
  41. ### for j to k ###
  42. for i = j to k
  43.     ...
  44.  
  45. ### for j to k by l ###
  46. for i = j to k by l
  47.     ...
  48.  
  49. ### for itératif ###
  50. for el in list
  51.     ...
  52.  
  53. ###
  54. while et for peuvent profiter d'un else
  55. il est exécuté seulement si la boucle n'est jamais
  56. parcourue
  57. ###
  58. while cond
  59.     ...
  60. else
  61.     ...
  62.  
  63. for ...
  64.     ...
  65. else
  66.     ...
  67.  
  68. ###
  69. --------------------
  70. Liste des opérateurs
  71. --------------------
  72. ###
  73. +     -     *     /    %     **
  74. +=    -=    *=    /=   %=    **=
  75. ^     |     &     ~    >>    <<    >>>
  76. ^=    |=    &=    ~=   >>=   <<=   >>>=
  77. ==    <     <=    >    >=    <>
  78. not   and   or
  79. --x   x--   ++x   x++
  80.  
  81. ###
  82. -------------------
  83. Notations numérique
  84. -------------------
  85. ###
  86. Int nbr = 123
  87. Int oct = 0o416
  88. Int hex = 0x1D6F
  89. Int bin = 0b1001001
  90.  
  91. ###
  92. ---------------
  93. Types primitifs
  94. ---------------
  95. ###
  96. Bool
  97. Num (et ses dérivés : Int, UInt, Long, ULong, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Float, Double, LDouble)
  98. Char
  99. String
  100.  
  101. ###
  102. ---------------
  103. Types complexes
  104. ---------------
  105. ###
  106. T[] ### est un tableau de T ###
  107. T{} ### est un dictionnaire de T ###
  108.  
  109. ### exemples ###
  110. Int[] ages = [ 8, 12, 16 ]
  111. Int monAge = ages.1
  112. Int monAge = ages[1]
  113.  
  114. Int{} ages = { yannick = 20, guillaume = 16, aurelie = 21 }
  115. Int monAge = ages.yannick
  116. Int monAge = ages["yannick"]
  117.  
  118. Int[][] cellules = [ [ 1, 1, 1 ], [ 1, 0, 1 ], [ 1, 1, 1 ] ]
  119. Int maCellule = cellules[1][1] ### 0 ###
  120.  
  121. ###
  122. ---------
  123. Fonctions
  124. ---------
  125. ###
  126. Num add(Num a, b)
  127.     return a + b
  128.  
  129. String add(String a, b)
  130.     return a + b
  131.  
  132. Int nb1 = 5
  133. Int nb2 = 10
  134. Int nb3 = add(nb1, nb2) ### 15 ###
  135.  
  136. String str1 = "Hello "
  137. String str2 = "World"
  138. String str3 = add(str1, str2) ### "Hello World" ###
  139.  
  140. ###
  141. ------------
  142. Enumérations
  143. ------------
  144. ###
  145. ### enum avec valeur automatique 0, 1, 2, ... ###
  146. enum Color
  147.     Red
  148.     Green
  149.     Blue
  150.  
  151. ### enum avec valeur assignée ###
  152. enum Color
  153.     Red   = 0xFF0000
  154.     Green = 0x00FF00
  155.     Blue  = 0x0000FF
  156.  
  157. ### utilisation ###
  158. Color myColor = Color.Red
  159.  
  160. ###
  161. -----
  162. Alias
  163. -----
  164. ###
  165. alias Number = Num
  166.  
  167. ###
  168. ----------
  169. Structures
  170. ----------
  171. ###
  172. struct Person
  173.     String firstname
  174.     String lastname
  175.     Int age
  176.  
  177. ### utilisation ###
  178. Person yannick = Person { firstname = "Yannick", lastname = "A", age = 20 }
  179.  
  180. String prenom = yannick.firstname
  181.  
  182. ###
  183. ----------
  184. Références
  185. ----------
  186. ###
  187. Void changerNom(ref Person p)
  188.     p.nom = "Manard"
  189.  
  190. ### yannick.nom vaut "A" ###
  191. changerNom(yannick)
  192. ### yannick.nom vaut "Manard" ###
  193.  
  194. Num a = 5
  195. Num b = ref a
  196.  
  197. b = 20
  198. ### a = 20 ###
Add Comment
Please, Sign In to add comment