Skip to content

Commit 88de519

Browse files
author
devjun10
committed
[CODE] Add goto example
- Add goto example
1 parent 4d38e05 commit 88de519

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

advanced/redis_utils.lua advanced/redis/redis_utils.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,13 @@ function M.get_bit(client, key, offset)
9494
end
9595

9696
function M.count_bits(client, key, start_index, end_index)
97-
return client:bitcount(key, start_index, end_index)
97+
local script = "return redis.call('bitcount', KEYS[1], ARGV[1], ARGV[2])"
98+
return client:eval(script, 1, key, start_index, end_index)
9899
end
99100

100101
function M.bitfield_operations(client, key, ...)
101-
return client:bitfield(key, ...)
102+
local script = "return redis.call('bitfield', KEYS[1], unpack(ARGV))"
103+
return client:eval(script, 1, key, ...)
102104
end
103105

104106
return M

basic/statements/main.lua

+38
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
local M = {}
22

3+
function M.classifyAge(age)
4+
if age < 0 then
5+
goto error_label
6+
end
7+
8+
if age < 13 then
9+
return "child"
10+
elseif age >= 13 and age < 20 then
11+
return "teenager"
12+
elseif age >= 20 and age < 65 then
13+
return "adult"
14+
else
15+
return "senior"
16+
end
17+
18+
:: error_label ::
19+
return "Invalid age"
20+
end
21+
322
function M.getMin(x, y)
423
if (x < y) then
524
return x
@@ -30,6 +49,15 @@ function M.repeatUntilNotEmpty()
3049
return line
3150
end
3251

52+
function M.repeatUntilNotEmptyControlStructures()
53+
local line
54+
:: repeat_start ::
55+
repeat
56+
line = io.read()
57+
until line ~= ""
58+
return line
59+
end
60+
3361
function sumWithWhile(start, _end)
3462
local sum = 0
3563
while (start <= _end) do
@@ -39,6 +67,16 @@ function sumWithWhile(start, _end)
3967
return sum
4068
end
4169

70+
function M.sumWithWhileControlStructures(start, _end)
71+
local sum = 0
72+
:: while_loop_start ::
73+
while (start <= _end) do
74+
sum = sum + start
75+
start = start + 1
76+
end
77+
return sum
78+
end
79+
4280
function M.sumWithFor(start, _end)
4381
local sum = 0
4482
for number = start, _end do

0 commit comments

Comments
 (0)