📜  朱莉娅关键词

📅  最后修改于: 2021-11-25 04:43:07             🧑  作者: Mango

Julia 中的关键字是对编译器具有预定义含义的保留字。它们被编译器用于一些内部进程。关键字不能用作变量名。这样做会导致编译时错误。
例子:

# Julia program to illustrate
# the use of keywords
  
# Using 'for' keyword 
for i in 1:10
      
    # Using if keyword
    if i % 2 == 0
        println(i, " is even")
      
    # Using else keyword
    else
        println(i, " is odd")
      
    # Using end keyword
    end
end

输出

1 is odd
2 is even
3 is odd
4 is even
5 is odd
6 is even
7 is odd
8 is even
9 is odd
10 is even

如果我们使用关键字作为变量名,编译器会产生一个错误:
Julia-01 中的关键字

Julia 中的重要关键字

baremodule
begin
break
catch
const
continue
do
else
elseif
end
export
false
finally
for
function
global
if
import
let
local
macro
module
quote
return
struct
true
try
using
while
 

有一些关键字,如abstract typemutable structprimitive type是保留的,但可以使用abstractmutableprimitivetype创建变量。
Julia-02 中的关键字