5 ms·
OK… So what does the first line of code do? You might as well say what the second line of code does - will save me time replying again ;)
by Donckele 4y ago
OK… So what does the first line of code do?
You might as well say what the second line of code does - will save me time replying again ;)
- deleted 4y ago[deleted]
- doctor_eval 4y agoI have never written a line of rust in my life but I assume that a statement that terminates with a value can be used as a rvalue in an assignment or other expression. So (I guess) both examples set the variable to 1.
- metaltyphoon 4y agoYes
- Donckele 4y agoThanks for that. That logic of the “break” keyword given a parameter is unusual compared to to other languages. Maybe it was a bad example to use.
- at_compile_time 4y agoRust is an expression-based language, so a loop block is just an expression. Break exits the loop and returns the expression following the keyword, which is the integer 1 in this example, but it could also be nothing if the loop returns nothing (aka unit "()", aka void in some languages), or any other expression as well.