The Lua Lua control structure -TTLSA (IV)

In Lua, all control building blocks are marked as an end to end. Result of an expression control structure can be any value, under Lua only false and nil as false, other values ​​are true. 1. if
if 条件 then
	...
end;	

if 条件 then
	...
else
	...
end;

if 条件 then 
	... 
elseif 条件 then
	... 
else 
	... 
end;
then keyword is used to mark the beginning of the code block conditions. 2. repeat
repeat 
	... 
until 条件
keyword is used to repeat the start flag code block, until the block end flag is used. Conditions of expression control structure located behind until keyword. 3. while
while 条件 
do 
	... 
end
while the repeat and control constructs, a code may be executed cyclically until a condition is satisfied. repeat control structure in the final determination condition, the block will be executed at least once. First, while the control structure determination condition and, if true, the code block is executed, it may never be executed. while the use of control structures do keyword for the block start mark. 4. for
for 变量=初值, 终点值, 步长
do
	... 
end

for 变量1, 变量2, ... 变量n in 表或枚举函数 
do 
	... 
end
Only determine the number of cycles in the first execution time. Initial value, terminal value, the step size is calculated only once, and before the loop is executed. The cyclic structure variables are local, after the end of the loop is once cleared. 5. break break statement is used to exit the current cycle. It can not be used outside the loop. 6. return return from the function to return the results. After the end there will be a natural function of a default return.

Reproduced in: https: //my.oschina.net/766/blog/211486

Guess you like

Origin blog.csdn.net/weixin_34387468/article/details/91493068