If Expression In Rust Programming

                                                          

        
    Sometimes we notice that we come across a situation in which we have to take decisions based on the conditions which might occur. In the same way, we can take decisions in a Rust program using an if expression. An If expression accepts a bool value and executes a block of code based on whether the value is true or false. If the value is true it executes the if block and if the value is false it executes the else block if present.
    We can get a bool value by declaring a bool variable and assigning it true or false. Another way is by using a relational operator i.e. <, >, ==, and so on.

                                                       


                    We can also return a value from an if expression. In the function article, we can learn about how to return a value from a block. When we put a semicolon at the end of an expression it becomes a statement and it doesn't return a value like an expression.

Happy reading. Keep in touch.

Comments

Popular posts from this blog

Programming Concepts Part I

Rust Hello World Program

Programming Concepts Part II