为什么有些语言需要分号? [英] Why do some languages need semicolons?

查看:52
本文介绍了为什么有些语言需要分号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在 Java 等语言中分号表示一行的结尾,但为什么呢?

I understand that semicolons indicate the end of a line in languages like Java, but why?

其他人经常问我这个问题,我真的想不出一个很好的方法来解释它如何比仅使用换行符或空格更好.

I get asked this a lot by other people, and I can't really think of a good way to explain how it works better than just using line breaks or white space.

推荐答案

它们不是表示行结束,而是表示语句结束.

They don't signal end of line, they signal end of statement.

有些语言不需要它们,但这些语言不允许在一行上有多个语句或单个语句跨越多行(没有一些其他信号,如 VB 的 _ 信号).

There are some languages that don't require them, but those languages don't allow multiple statements on a single line or a single statement to span multipile lines (without some other signal like VB's _ signal).

为什么有些语言允许一行中有多个语句?哲学是空白是无关紧要的(行尾字符是空白).这允许在如何格式化代码方面具有灵活性,因为格式化不是语义含义的一部分.

Why do some languages allow multiple statements on a line? The philosophy is that whitespace is irrelevant (an end of line character is whitespace). This allows flexibility in how the code is formatted as formatting is not part of the semantic meaning.

这篇关于为什么有些语言需要分号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆