Nimã®åºæ¬æ§æ
ã¾ããä»ã®è¨èªã«ããããããªåºæ¬çãªæ§æãç´¹ä»ãã¦ããã¾ãã
Hello World
ã¾ãã¯æåã®ä¸æ©ã®HelloWorldã§ãã
echo "Hello World!!"
ããã¯ã
echo("Hello World!!")
ããã¨åãæå³ã§ãã
Nimã§ã¯ãrubyã®ããã«é¢æ°å¼ã³åºãã®å ´åã«æ¬å¼§ãçç¥ãããã¨ãã§ãã¾ããããããå ´åã«ãã£ã¦ã¯æ¬å¼§ãä»ããå¿
è¦ãããã®ã§ããã¯æ³¨æã§ãã
å¤æ°ãå®æ°ãã³ã³ãã¤ã«æå®æ°
ãããããvarï¼å¤æ°ï¼ãletï¼å®æ°ï¼ãconstï¼ã³ã³ãã¤ã«æå®æ°ï¼ã«ãªãã¾ãã
var name = "Hello!!" echo name name = "Rewrite!!" echo name
let name = "Hello!!" echo name
const name = "Hello!!" echo name
å¤ãæ示ã®å ´åãåæ¨è«ãããã¾ããããããå¤ãç¡ã(Nimã®å ´åã¯nil
)å ´åãå宣è¨ãå¿
è¦ã§ãã
var name: string name = "Hello!!"
æ¡ä»¶åå²
æ§æã¨ãã¦ã¯Pythonã®ãããªif elif else
ã§ãã
çå½å¤ã¯true bool
ã§ãã
if true: echo "True!!" else: echo "False!!"
Nimã¯æ§é ã表ç¾ããææ³ã¨ãã¦ãPythonã®ãããªã¤ã³ãã³ãå½¢å¼ãæ¡ç¨ãã¦ãã¾ããåºæ¬çã«ã¯ã¹ãã¼ã¹2ã¤ã§è¡¨ç¾ãã¾ãã
ä»ã«ããcase of
æ§æãããã
var name = "hello" case "hello" of "hello": echo 1 of "world": echo 2 else: echo 3
ã®ããã«æ¸ãã¾ãã
ä»ã«ãwhenãããã¾ãããããã¯ã³ã³ãã¤ã«æåå²ã§ãã
ç¹°ãè¿ãæ§æ
ç¹°ãè¿ãæ§æã¯ãfor while
ãããã¾ãã
for i in 1..5: echo i
var i = 0 while i < 5: echo i i += 1
for whileã®ä¸¡æ¹ã§break continue
ã使ãã¾ãã
..
ã¯ããããRangeã§ãã
é åãã«ã¼ãããéã«ãã
var arr = [1, 2, 3, 4, 5] for val in arr: echo val
ãã®ããã«æãã¾ãã
indexã§åããã¨ãã§ãã¾ãã
var arr = [1, 2, 3, 4, 5] for i in 0..arr.len-1: echo arr[i]
ãããããã®å ´åã«ã¯..<
æ¼ç®åã§ã
var arr = [1, 2, 3, 4, 5] for i in 0..<arr.len: echo arr[i]
ã®ããã«æ¸ããã¨ãã§ãã¾ãã
é¢æ°
é¢æ°ã¯Nimã§ã¯æç¶ãã¨è¨ããã¦ãããæ§æã¨ãã¦ã¯proc
ã«ãªãã¾ãã
proc add5(val: int): int = return val + 5
é¢æ°å®£è¨ã§ã¯åã®çç¥ã¯ã§ãã¾ããã
returnã§æ»ãå¤ãè¿ãã¦ãã¾ãããä»ã«æ»ãå¤ãè¿ãæ¹æ³ã¨ãã¦ãresultã«ä»£å ¥ããã¨ããæ¹æ³ãããã¾ãã
proc add5(val: int): int = result = val + 5
ã¾ã¨ã
以ä¸ãNimã®åºæ¬æ§æã«ãªãã¾ãããããNimã¯ãã®ä»ã®æ©è½ãè±å¯ãªã®ã§ããã¯ã¾ãå¥ã®è¨äºã«æãããã¨æãã¾ãã