Python Language                
            함수 내에서 루프 사용
        
        
            
    수색…
소개
Python 함수에서 "return"문이 실행되는 즉시 반환됩니다.
함수 내의 루프 내부의 return 문
이 예제에서, 함수는 값 var가 1
def func(params):
    for value in params:
        print ('Got value {}'.format(value))
        if value == 1:
            # Returns from function as soon as value is 1
            print (">>>> Got 1")
            return
        print ("Still looping")
    return "Couldn't find 1"
func([5, 3, 1, 2, 8, 9])
산출
Got value 5
Still looping
Got value 3
Still looping
Got value 1
>>>> Got 1
Modified text is an extract of the original Stack Overflow Documentation
        아래 라이선스 CC BY-SA 3.0
        와 제휴하지 않음 Stack Overflow