break์™€ continue

๋‹ค์Œ ๋ฐ˜๋ณต์„ ์ฆ‰์‹œ ์‹œ์ž‘ํ•˜๋ ค๋ฉด continue๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

If you want to exit any kind of loop early, use break. For loop, this can take an optional expression that becomes the value of the loop expression.

fn main() {
    let mut i = 0;
    loop {
        i += 1;
        if i > 5 {
            break;
        }
        if i % 2 == 0 {
            continue;
        }
        println!("{}", i);
    }
}