|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
Default values of variablesWhen you declare a variable in C and do not initialize it, it'll have a garbage value.
Nim, on the other hand, implicitly initializes every declared variable if you do not assign a value to it. The memory location of a primitive variable will be filled with zeroes. When you declare a string, it'll be an empty string (and not a
Output: a: 0 b: false c: '�'; ASCII code: 0 d: 0.0 s: ''; length: 0 TipHowever, explicit is better than implicit. When you need a counter, I think it's a good practice to explicitly set its value to # var counter: int # it would also work since its initial value would be 0 var counter = 0 # explicit, easier to read for i in 1..5: # executed 5 times counter += 1 echo counter # 5 |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |