#while문
'''
while 조건:
    반복할 명령
'''
i = 3
while i > 0:
    print(i)
    i -= 1 #i = i - 1
print('끝!')

a = 1
while a <= 5:
    print(a)
    a += 2

#break : 반복문을 강제로 멈추는 명령어
while True:
    print('반복')
    break
    print('a')

b = 3
while True:
    print(b)
    if b == 5:
        break
    b += 1

c = 20
while True:
    print(c)
    if c == 10:
        break
    c -= 5

#continue : 반복을 멈추지 않고, 특정 조건일 때만 아래 코드 건너뛰기
d = 0
while d < 10:
    d += 2
    if d == 6:
        continue
    print(d)
    
print('----문제1----')
n = 1
sum = 0
while n <= 100:
    sum += n 
    n += 1
print(sum)

print('----문제2----')
total = 0
while total < 50:
    #사용자에게 숫자를 계속 입력받습니다.
    num = int(input())

    #입력한 숫자가 음수이면 건너뛰고,
    if num < 0:
        continue

    # 0 이상 숫자는 모두 더합니다.
    total += num

    # 누적된 합이 50 이상이 되면 반복을 멈춥니다.
    # if total >= 50:
    #     break

print('합계', total)


Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: