Rust is a systems programming language that emphasizes performance, safety, and concurrency. Control flow in Rust allows you to manage program execution using structures like if expressions, loops, and pattern matching. These tools enable clear and efficient handling of conditional logic and iteration.
if statement in Rust?
if expression in Rust?
if x > 10 { println!("x is greater than 10"); }if (x > 10) { println!("x is greater than 10"); }if x > 10: println!("x is greater than 10");if x > 10 { println[x is greater than 10]; }if expression return a value?
else is usedfor loopselse block with an if expression in Rust?
if condition { ... } else condition { ... }if condition { ... } else { ... }if { ... } else { ... }if condition -> { ... } else { ... }if expression in Rust?
if expressionif expression is false in Rust?
if block will execute.else block will execute.else if block will execute.if expressions?
if expressions must always return a value.if expressions can optionally return values.if expressions cannot return values.if expressions are only valid for comparison operations.if and else branches return a value in Rust?
else inside if without a return statement.if expression be used as a condition for a loop in Rust?
while and for can be used.match expressions.if expression cannot be used in this context.if expression returning a value?
let result = if x > 10 { "Greater" } else { "Lesser" };let result = if x > 10 => "Greater" else => "Lesser";let result = if x > 10 -> "Greater"; else -> "Lesser";let result = if (x > 10) { "Greater" } else "Lesser";loop in Rust?
loop { ... }loop => { ... }loop { ... end }loop: { ... }break in a loop?
exitbreakcontinuereturnfor loop in Rust?
for i in 0..10 { ... }for i in 10..0 { ... }for i = 0 to 10 { ... }for i until 10 { ... }while loop in Rust?
break.continue statement is encountered in a loop in Rust?
for loop iterate over an array in Rust?
for element in array { ... }for array { ... }for i in range { ... }for element in range { ... }loop?
while loop.break is used.whileforloopcontinuefor loop in Rust?
exit.break.continue.skip.match expression in Rust?
match expression in Rust?
caseswitchmatchpatternmatch expression handle non-exhaustive patterns?
default case.match expression in Rust?
match x { 1..5 => "Low", _ => "High" }match x { 1..5 -> "Low", _ => "High" }match x { _ => "Any" }match { x > 5 } { _ => "High" }_ pattern in Rust’s match expression?
match expression in Rust?
match will not execute.match statement.match expression to match on an enum in Rust?
match EnumType::Variant { ... }match Enum { Variant => ... }match { EnumType } { Variant => ... }match Enum { ... }match expressions with integers in Rust?
match expressions are only for strings.match expression in Rust covers all cases?
default keyword.else clause.* wildcard.match expression is correct?
match expressions require an else block.match expressions always result in a true/false evaluation.match is exhaustive and must account for all possibilities.match expressions are only used for string matching.| Qno | Answer |
|---|---|
| 1 | B) Expression |
| 2 | A) if x > 10 { println!("x is greater than 10"); } |
| 3 | A) Yes |
| 4 | B) if condition { ... } else { ... } |
| 5 | D) As a statement without a block |
| 6 | B) The code inside the else block will execute. |
| 7 | B) if expressions can optionally return values. |
| 8 | B) Use the same type of value in both branches. |
| 9 | A) Yes, it can evaluate to a boolean. |
| 10 | A) let result = if x > 10 { "Greater" } else { "Lesser" }; |
| 11 | A) loop { ... } |
| 12 | A) The loop will run indefinitely. |
| 13 | B) break |
| 14 | A) for i in 0..10 { ... } |
| 15 | C) It runs as long as a specified condition is true. |
| 16 | B) The next iteration of the loop starts. |
| 17 | A) for element in array { ... } |
| 18 | C) It is an infinite loop unless break is used. |
| 19 | B) for |
| 20 | C) Use continue. |
| 21 | B) To handle conditional branching based on multiple patterns |
| 22 | C) match |
| 23 | A) It automatically raises an error. |
| 24 | A) match x { 1..5 => "Low", _ => "High" } |
| 25 | B) To create a fallback or catch-all pattern |
| 26 | A) The program crashes. |
| 27 | A) match EnumType::Variant { ... } |
| 28 | A) Yes, it is a common use case. |
| 29 | B) Ensure all possible patterns are specified. |
| 30 | C) match is exhaustive and must account for all possibilities. |