기본문법
Python
if True: print("code1") print("code2") print("code3")
Ruby
if true puts("code1") puts("code2") end puts("code3")
실행결과
code1 code2 code3
조건문의 활용
Python
input = 11 real = 11 if real == input: print("Hello!")
Ruby
input = 11 real = 11 if real == input puts("Hello!") end
실행결과
Hello!
else
Python
input = 11 real = 11 if real == input: print("Hello!") else: print("Who are you?")
Ruby
input = 11 real = 11 if real == input puts("Hello!") else puts("Who are you?") end
실행결과
Hello!
else if
Python
input = 33 real_egoing = 11 real_k8805 = "ab" if real_egoing == input: print("Hello!, egoing") elif real_k8805 == input: print("Hello!, k8805") else: print("Who are you?")
Ruby
input = 33 real_egoing = 11 real_k8805 = "ab" if real_egoing == input puts("Hello!, egoing") elsif real_k8805 == input puts("Hello!, k8805") else puts("Who are you?") end
실행결과
Who are you?