语句和功能之间的区别 [英] Difference between statement and function
问题描述
快到午夜了,我脑子里只有一个问题是for loop一个声明或一个函数。
It's almost midnight and I just got a question in my head is "for loop" a statement or a function.
我一直认为这是一个声明,但是我做了谷歌搜索它是一个功能,确实有结果。那是什么?在那种情况下,函数和语句之间的区别是什么?
I always thought it is a statement, but I did a google search on it being a function and there are indeed results for that. So what is it? And in that case what is the difference between function and statement?
推荐答案
for循环通常不是函数,它是一种称为流量控制结构的特殊语句。
A for loop is a not usually a function, it is a special kind of statement called a flow control structure.
A 声明 是一个命令。它做了一些事情。在大多数语言中,语句不返回值。示例:
A statement is a command. It does something. In most languages, statements do not return values. Example:
print "Hello World"
功能 是一个子程序,可以在程序的其他地方调用。函数通常(但不一定)返回值。示例:
A function is a subroutine that can be called elsewhere in the program. Functions often (but not necessarily) return values. Example:
function(a) { return a * 2 }
控制结构 ,也称为复合语句,是一种用于指导执行流程的语句。示例:
A control structure, also known as a compound statement, is a statement that is used to direct the flow of execution. Examples:
if (condition) then { branch_1 } else { branch_2 }
for (i = 0; i < 10; i += 1) { ... }
另外值得注意的是 表达式 是一段评估为值的代码。示例:
Also worth noting is that an expression is a piece of code that evaluates to a value. Example:
2 + 2
所有示例都是伪代码,不依赖于任何特定语言。另请注意,这些不是独家类别,它们可以重叠。
这篇关于语句和功能之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!