lua論理演算子およびループ文

1038 ワード

--lua     false     nil    

-- and             (false     nil      ),          

print(1 and 5)
print(0 and 6)
print(false and 1)
print(nil and 2)


print("--------------------------")

-- or            ,      ,            

print(1 or 5)
print(0 or 6)
print(false or 1)
print(nil or 2)

print("--------------------------")

-- not        true     false

print(not 1)
print(not fasle)
print(not nil)
print(not 0)



-- while       do    end         

local index = 1

local my_table = {1,2,3}

while my_table[index] do
	--todo
	print(my_table[index])
	index = index +1  --  lua   ++        
end


-- repeat          do while         while       do  end 
local snum = 1
repeat
	--todo
	print("snum value is "..snum)
	snum = snum +1
until snum == 10



--for       #my_table               size_of

for i=1,#my_table do
	print(my_table[i])
end


--    2                  1     

for i=1,10,2 do
	print(i)
end

--             -1
print("------------")
for i=20,10,-1 do
	print(i)
end