For Programmer

7. 반복문(while문,for문) 본문

코팅테스트/파이썬 문법 정리

7. 반복문(while문,for문)

유지광이 2021. 8. 10. 12:57
728x90

1. while문

i = 1
result = 0

#i가 9보다 작거나 같을 때 아래 코드를 반복적으로 실행
while i <= 9:
  if i % 2 == 1:
      result += i
  i += 1
print(result)

2. for문

array = [1,2,3,4,5]

for x in array:
      print(x, end=" ")

for문 안에서 range 사용하기 + continue키워드 사용하기

break 키워드

반복문 예제

728x90
Comments