컨테이너와 반복문의 만남
Python
members = ['egoing', 'leezche', 'graphittie'] i = 0 while i < len(members): print(members[i]) i = i + 1
Ruby
members = ['egoing', 'leezche', 'graphittie'] i = 0 while i < members.length do puts(members[i]) i = i + 1 end
실행결과
egoing leezche graphittie
달콤한 for문의 등장
Python
members = ['egoing', 'leezche', 'graphittie'] for member in members: print(member)
Ruby
members = ['egoing', 'leezche', 'graphittie'] for member in members do puts(member) end
실행결과
egoing leezche graphitti
for문의 활용
Python
for item in range(5, 11): print(item)
Ruby
for item in (5..10) do puts(item) end
실행결과
5 6 7 8 9 10
로그인 애플리케이션에 투입
Python
input_id = input("아이디를 입력해주세요.\n") members = ['egoing', 'k8805', 'leezche'] for member in members: if member == input_id: print('Hello!, '+member) import sys sys.exit() print('Who are you?')
Ruby
puts("아이디를 입력해주세요") input_id = gets.chomp() members = ['egoing', 'k8805', 'leezche'] for member in members do if member == input_id puts('Hello!, '+member) exit end end puts('Who are you?')
실행결과
입력 값에 따라서 달라요~