Boo 언어의 if...else... 구문은 Python 언어의 그것과 동일하다.
if 조건식:
......
elif 조건식:
......
elif 조건식:
.......
else:
......
Boo 언어의 주석문은 Python 언어의 것을 써도 되고, C 언어의 것을 써도 된다.
한 줄 주석문
// 주석...
또는
# 주석...
여러 줄 주석문
/*
주석...
*/
또는
"""
주석...
"""
소스 파일명: testIf.boo
- """
- Filename: testIf.boo
- Purpose: Example using the conditional control structure syntax
- if .... else ...
- Execute: booi testIf.boo [number]
- """
- import System // Convert.ToDouble()과 Environment.Exit()을
- // 사용하기 위한 Boo 언어의 수입(import) 구문
- # 사용법을 보여주는 함수
- def printUsing():
- print("Using: booi testIf.boo [number]")
- print("This determines whether the number is positive or not.")
- # 명령행 인자의 개수가 1이 아니면 사용법을 보여준다.
- if argv.Length != 1:
- printUsing()
- Environment.Exit(1)
- # 명령행 인자의 스트링을 가져와서
- # 배정밀도 부동소수점수로 변환하여
- # 변수 val에 저장한다.
- val as double = Convert.ToDouble(argv[0])
- # 변수 val에 저장된 값이 양수인지 음수인지 0인지를
- # 판단하는 if...else... 조건문
- if val > 0.0:
- print("${val} is a positive number.")
- elif val < 0.0:
- print("${val} is a negative number.")
- else:
- 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.
'프로그래밍 > Boo' 카테고리의 다른 글
80컬럼 컨솔에 19단표 출력하기 예제 for Boo (0) | 2009.04.01 |
---|---|
(최대공약수 구하기) while... 반복문 예제 for Boo (0) | 2009.04.01 |
명령행 인자 처리 예제 for Boo (0) | 2009.04.01 |
구구단 출력 예제 for Boo (0) | 2009.04.01 |
Hello 예제 for Boo (0) | 2009.03.31 |