📜  朱莉娅关键字

📅  最后修改于: 2022-05-13 01:55:03.616000             🧑  作者: 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

如果我们使用关键字作为变量名,编译器会报错:
关键字-in-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的变量。
关键字-in-Julia-02