basic/base-type/statement-expression #706
Replies: 17 comments 17 replies
-
在想一个问题:既然表达式的定义是“会进行求值然后返回一个值”,那能否将rust中所有的代码块都理解成表达式,只是带分号的表达式返回值是()? |
Beta Was this translation helpful? Give feedback.
-
其实本质上就是没有分号(;)的区别,有的话执行完接着执行或结束,没有的话,执行完就返回。非要拆分成“表达式”和“语句”的概念,感觉有点刻意。 刚开始学,还体会不到其中的深意…… |
Beta Was this translation helpful? Give feedback.
-
表达式和语句的官方标准定义是什么? |
Beta Was this translation helpful? Give feedback.
-
GPT 的回答: |
Beta Was this translation helpful? Give feedback.
-
新人求教,下面的函数返回其实是等价的? |
Beta Was this translation helpful? Give feedback.
-
let y = if x % 2 == 1 { |
Beta Was this translation helpful? Give feedback.
-
表达式不能包含分号!! |
Beta Was this translation helpful? Give feedback.
-
大佬们,不知道是不是我理解的有问题,表达式那里举的第一个例子里面的 let y = {
let x = 3;
x + 1
}; 这里的 |
Beta Was this translation helpful? Give feedback.
-
为什么以下不会报错呢? (a,c) 中的a,和第一句中的a,是不同的么 |
Beta Was this translation helpful? Give feedback.
-
这其实应该解释下控制流中的特殊表达式:表达语句 expression statement。 也就是return, break, continue这几个,他们要不要分号都可以。 |
Beta Was this translation helpful? Give feedback.
-
;(愤怒脸):我给你返个蛋() |
Beta Was this translation helpful? Give feedback.
-
mark: 真的大爱这种学习方式,通过更多读者评论,还能得到更多详细理解解答! |
Beta Was this translation helpful? Give feedback.
-
您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。
|
Beta Was this translation helpful? Give feedback.
-
表达式不能包含分号。 |
Beta Was this translation helpful? Give feedback.
-
我还是坚持 使用 return |
Beta Was this translation helpful? Give feedback.
-
那我还是习惯 return xx; |
Beta Was this translation helpful? Give feedback.
-
fn _test_expression(a: i32, b: i32) -> i32 {
return a + b
}
请问这里的return a + b是表达式还是语句呢
|
Beta Was this translation helpful? Give feedback.
-
basic/base-type/statement-expression
https://course.rs/basic/base-type/statement-expression.html
Beta Was this translation helpful? Give feedback.
All reactions