通过lua自带例子学习lua 02

-- Example 6 -- Case Sensitive.

-- Lua is case sensitive so all variable names & keywords
-- must be in correct case.

ab=1
Ab=2
AB=3
print(ab,Ab,AB)

 

-------- Output ------

1 2 3

-- Example 7 -- Keywords.

-- Lua reserved words are: and, break, do, else, elseif,
-- end, false, for, function, if, in, local, nil, not, or,
-- repeat, return, then, true, until, while.

-- Keywords cannot be used for variable names,
-- 'and' is a keyword, but AND is not, so it is a legal variable name.
AND=3
print(AND)

 

-------- Output ------

3

-- Example 8 -- Strings.

a="single 'quoted' string and double \"quoted\" string inside"
b='single \'quoted\' string and double "quoted" string inside'
c= [[ multiple line
with 'single'
and "double" quoted strings inside.]]

print(a)
print(b)
print(c)


-------- Output ------

single 'quoted' string and double "quoted" string inside
single 'quoted' string and double "quoted" string inside
multiple line
with 'single'
and "double" quoted strings inside.

-- Example 9 -- Assignments.

-- Multiple assignments are valid.
-- var1,var2=var3,var4

a,b,c,d,e = 1, 2, "three", "four", 5

print(a,b,c,d,e)

 

-------- Output ------

1 2 three four 5

-- Example 10 -- More Assignments.

-- Multiple assignments allows one line to swap two variables.

print(a,b)
a,b=b,a
print(a,b)

 

-------- Output ------

1 2
2 1

 

posted on 2013-04-06 15:17  cv_ml_张欣男  阅读(255)  评论(0编辑  收藏  举报

导航