Lua replacement for the % operator

前端 未结 6 1699
臣服心动
臣服心动 2020-12-30 19:39

I want to check, if a number is divisible by another number:

for i = 1, 100 do
    if i % 2 == 0 then
        print( i .. \" is divisible.\")
    end
end
         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-30 20:29

    for i = 1, 100 do
        if (math.mod(i,2) == 0) then
            print( i .. " is divisible.")
        end
    end
    

提交回复
热议问题