While a == 10 incorrect?

โš“ Rust    ๐Ÿ“… 2025-11-22    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 11      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: While a == 10 incorrect?

Why does the rustc compiler successfully compile code that contains a logically incorrect condition?

fn main() {
let mut a = 1;
while a == 10 {

    println!("{}", a);
    a += 1;

}

}

The compiled binary doesnโ€™t produce any output, but intuitively, the compiler should detect that the loop condition (a == 10) will never be true.

4 posts - 4 participants

Read full topic

๐Ÿท๏ธ Rust_feed