-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathex02.lua
More file actions
21 lines (20 loc) · 736 Bytes
/
ex02.lua
File metadata and controls
21 lines (20 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
-- Example 2. Emulating "continue" with goto
local function open_files(filenames)
for i = 1, #filenames do
local text = ""
local f = io.open(filenames[i])
if f then
text = f:read("a")
if not text then goto continue end -- cannot read
f:close()
--8<----------------------------------------------------------------------
print('opened', filenames[i])
--8<----------------------------------------------------------------------
end
--[[ process text ]]
::continue::
end
end
--8<----------------------------------------------------------------------------
open_files{'/etc/shadow','/etc/fstab'}
--8<----------------------------------------------------------------------------