# Lua learning notes – (2) – loop statements

Time：2020-9-28
``````--1. While loop
--a=1
--while(a<=20) do
--  if a%2==1 then
--    print(a)
--  end
--  a=a+1
--end

--2. Numerical for loop
--b=2
--sum=0
--for i=1,100,1 do
--  sum=sum+i
--  print(sum)
--end
--print("-------------")
--print(sum)
--

--3. Generic for loop
--tab1={ one=1, two=2, three=3, four=4, five=5}
--for k,v in pairs(tab1) do
--  print(k..'='..v)
--end
--

--4. Generic for loop 2
--local tbl2 = {"apple", "pear", "orange", "grape"}
--for k,v in pairs(tbl2) do
--  print(k, v)
--end
--

--5. Repeat until loop
c=1
repeat
print(c)
c=c+2
until
c>=100``````

## Solutions to leetcode problems and knowledge points 1. Sum of two numbers

Title Link 1. Two Sum  difficulty: \$/ color {00965e} {easy}\$ Knowledge points 1. Hash (hash) function The classic hash function times33 is widely used, and the core algorithm is as follows: hash(i) = hash(i-1) * 33 + str[i] Laruence has an article about:Hash algorithm in PHP 2. Hash collision processing method 2.1 chain address method […]