|
Oktatás * Programozás 1 * Szkriptnyelvek Teaching * Programming 1 (BI) Félévek Linkek * kalendárium |
Nim2 /
How to return a value from a functionThere is the classical way: proc twice(n: int): int = return 2 * n You can omit the proc twice(n: int): int = 2 * n Since the body is very short here, you can do it in just 1 line (short form): proc twice(n: int): int = 2 * n When you have a function, a variable called proc twice(n: int): int = # var result: int # you get this implicitly result = 2 * n Another example: proc my_counter(): int = result = 0 # optional, result is implicitly initialized with 0 for i in 1..5: result += 1 let value = my_counter() echo value # 5 Here, the variable |
![]() Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |