CX::Next — 다음(next) 제어 예외

CX::Next — 다음(next) 제어 예외

루프에서 next로 다음 반복으로 넘어갈 때, 내부적으로는 특정 제어 예외가 발생해요. 그 예외가 바로 CX::Next입니다.

출처: Raku 공식 문서 — CX::Next

본문

class CX::Next does X::Control { }

next가 호출될 때 발생하는 제어 예외(control exception)예요.

for ^10 {
    CONTROL {
      when CX::Next { say "We're next" };
    }
    next if $_ %% 2;
    say "We're in $_";
}

이 코드는 다음과 같이 출력해요:

We're next
We're in 1
We're next
We're in 3
We're next
We're in 5
We're next
We're in 7
We're next
We're in 9

메서드

method message

method message()

'<next control exception>' 문자열을 반환해요.