Directory Image
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Privacy Policy.

What is Control Flow in Rust?

Author: Mansoor Ahmed
by Mansoor Ahmed
Posted: Oct 24, 2020
  • A control flow is the order in which the piece of program is executed.

  • In control flow we have following expressions:

  1. If expression
  2. Else expression
  3. Else if expression

If Expression:

  • If expression allows to branch your code to any condition.

  • If the condition is true then the program in if block will be executed.

  • When if expression is not true then the program will be passed to further blocks of else if expressions or else expression.

  • The curly brackets defining the program blocks are called arms.

Else Expression:

  • Else expression gives the program an alternative block of code to execute when the condition introduced in if block evaluates to false.

  • Else expression comes at last.

Example

fn main() {

let number = 3;

if number

About the Author

Mansoor Ahmed Chemical Engineer,Web developer

Rate this Article
Leave a Comment
Author Thumbnail
I Agree:
Comment 
Pictures
Author: Mansoor Ahmed

Mansoor Ahmed

Member since: Oct 10, 2020
Published articles: 124

Related Articles