Skip to content

while 与 if

while / if 的风格与 python 没有差异

import std/strutils
import std/strformat

# while statement
while true:
  echo "Which videocard does linux respect most?"
  let card = stdin.readLine
  let lower = card.toLower
  if lower == "nvidia":
    echo &"So {card} fxxk you!"
  elif lower == "amd":
    echo "AMD YES!"
  else:
    echo "No, that's wrong!"

& 是格式化字符串的简洁表示方法, 本节不赘述