Rust - Decision Making Flashcards

1
Q

Give the possiblites of decision making

A

1 if statement
An if statement consists of a Boolean expression followed by one or more statements.

2 if…else statement

An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.

3 else…if and nested ifstatement

You can use one if or else if statement inside another if or else if statement(s).

4 match statement

A match statement allows a variable to be tested against a list of values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Give a code example of if statment

A

let num = 5;
if num> 6 {
println!(“{} is greater than 6”, num);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give an example of if..else and nested

A

let num = 12;
if num % 2==0 {
println!(“Even”);
} else {
println!(“Odd”);
}

let num = 2 ;
if num > 0 {
println!(“{} is positive”,num);
} else if num < 0 {
println!(“{} is negative”,num);
} else {
println!(“{} is neither positive nor negative”,num) ;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe match statement

A

The match statement checks if a current value is matching from a list of values, this is very much similar to the switch statement in C language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Give an example of match statement

A

let state_code = “MH”;

let state = match state_code{
“MH” => {
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly