shlogg · Early preview
Jeff Mitchell @sentinel1909

Rust Decision Logic: If, Else, And Else If Expressions

Rust's basic decision logic: `if`, `else if` & `match`. Control flow with conditional statements for different code paths & outcomes. Learn how to make decisions in your Rust programs!

Software capability would be very limited if there were no ability to make decisions and follow different logic paths. The ability to branch and provide different outcomes, based on either internal results or external user input, is essential. Rust provides basic decision logic in the form of the if and else if expressions.

  
  
  The if Expression

An if expression starts with the if keyword and is followed by a condition. Immediately after the condition is a block of code, surrounded by curly braces, which is executed if the condition proves true. If the condition is not true, the code aft...