Labeled Statements

장주명·2021년 5월 20일
0

반복문 if문 switch문에서 주로 사용한다. 또한 원하는 문장을 종료시키고자 할때 사용된다.

동일한 label로 지정된 문장을 제어시키는 방법

for i in 1...3{
    print("Outer Loop",i)
    
    for j in 1...3{
        print("innder Loop" , j)
        break // 안쪽에서만 영향을 미친다.
    }
}


outer: for i in 1...3{
    print("Outer Loop",i)
    
    for j in 1...3{
        print("innder Loop" , j)
        break outer // 이 브레이크는 내부가 아닌 밖의 outer라는 이름으로 지정해준 문장을 종료하게 된다.
    }
}
profile
flutter & ios 개발자

0개의 댓글

관련 채용 정보