Boo  언어의 if...else... 구문은 Python 언어의 그것과 동일하다.

        if 조건식:
                ......
        elif 조건식:
                ......
        elif 조건식:
                .......
        else:
                ......


Boo  언어의 주석문은 Python 언어의 것을 써도 되고, C 언어의 것을 써도 된다.

     한 줄 주석문
            // 주석...
       또는
            # 주석...

     여러 줄 주석문
            /*
                    주석... 
                    */
       또는
            """
                    주석...       
                    """


소스 파일명: testIf.boo

  1. """
  2.    Filename: testIf.boo
  3.    Purpose:  Example using the conditional control structure syntax
  4.                  if .... else ...
  5.    Execute: booi testIf.boo [number]
  6. """
  7. import System    // Convert.ToDouble()과 Environment.Exit()을
  8.                  // 사용하기 위한 Boo 언어의 수입(import) 구문
  9. # 사용법을 보여주는 함수
  10. def printUsing():
  11.    print("Using: booi testIf.boo [number]")
  12.    print("This determines whether the number is positive or not.")
  13. # 명령행 인자의 개수가 1이 아니면 사용법을 보여준다.
  14. if argv.Length != 1:
  15.     printUsing()
  16.     Environment.Exit(1)
  17. # 명령행 인자의 스트링을 가져와서
  18. # 배정밀도 부동소수점수로 변환하여
  19. # 변수 val에 저장한다.
  20. val as double = Convert.ToDouble(argv[0])
  21. # 변수 val에 저장된 값이 양수인지 음수인지 0인지를
  22. # 판단하는 if...else... 조건문
  23. if val > 0.0:
  24.     print("${val} is a positive number.")
  25. elif val < 0.0:
  26.     print("${val} is a negative number.")
  27. else:
  28.     print("${val} is zero.")




실행> booi testIf.boo
Using: booi testIf.boo [number]
This determines whether the number is positive or not.

실행> booi testIf.boo 6.25
6.25 is a positive number.

실행> booi testIf.boo -6.25
-6.25 is a negative number.

실행> booi testIf.boo 0
0 is zero.


※ 컴파일 명령 booc로 위의 소스 코드로 부터 .NET용 실행파일을 만들 수 있다.
booc testIf.boo

컴파일> booc -out:TestIf.exe testIf.boo
실행> TestIf 1.02
1.02 is a positive number.

실행> TestIf -1.02
-1.02 is a negative number.

실행> TestIf 0
0 is zero.



 

크리에이티브 커먼즈 라이선스
Creative Commons License

Posted by Scripter
,