Hard deck/Deep dive

공간의 끝 / While and For space

서버관리자 페페 2022. 8. 3. 13:18
// Operating Palindrome(2/2)
int i =  N;
while (true) {
    if (A[i] != 0) {
        int result = A[i];

        // Output Extracting Cable
        if (isPalindrome(result)) {
            System.out.println(result);
            break;
        }
    }
    i++;
}

공간의 끝과 시행횟수가 명확하다면 for로 쓸 수 있지만,
그러지 못한 경우 우선 while(true)로 kaiten 시킨 후에, 끝의 조건인 if 와 break;를 설정한다 i++는 시행간격(for)와 동일

for는 실행되기 전 이미 시행공간 배치가 완료, projected된 것
while은 projecting하는 potetntial을 가지고 있으며 실행시에 확인 가능


 

// Output Extracting Cable
while (result > 0) {
    bw.write("1");
    result--;
}
bw.flush();
bw.close();

while 공간이 수축하며 kaiten한다 

 

private static long GCD(long B, long S) {
    long r = B%S;
    (while r != 0) {
        r = B%S;
        B = S;
        S = r;
    }
    return Math.abs(B);
}

while은 특정 숫자가 조건에 수렴할 때까지 간다(벗어난다)