while True:
    print('계속 반복 중')
    break

#break : 반복문을 강제로 멈추게 하는 명령어
i = 0
while True:
    print('+')
    if i == 3:
        break
    i = i + 1

print(i)


#while : 몇 번 반복할지 모를 때
#for : 몇 번 반복할지 미리 알고 있을 때

sum = 0
n = 1
while sum + n < 100:
    sum = sum + n
    n = n + 1
print(sum, n)


total = 0
for j in range(1,14):
    total = total + j
print(total)


print('----문제----')
candy = 1
while True:
    print(candy, "번째 사탕을 먹습니다")
    if candy == 5:
        print("배가 아파서 그만 먹습니다")
        break
    candy = candy + 1






Embed on website

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