I'm starting to learn Lua and in one part of the book I need to convert a Maze Game that uses goto to another one that doesn't use goto.The maze is the simplest ever made, starting from room #1:---------| 1 | 2 |---------| 3 | 4 |---------This is the original version using goto from the book:goto room1 -- initial room::room1:: do  local move = io.read()  if move == south then goto room3  elseif move == east then goto room2  else    print(invalid move)    goto room1 -- stay in the same room  endend::room2:: do  local move = io.read()  if move == south then goto room4  elseif move == west then goto room1  else    print(invalid move)    goto room2  endend::room3:: do  local move = io.read()  if move == north then goto room1  elseif move == east then goto room4  else    print(invalid move)    goto room3  endend::room4:: do  print(Congratulations, you won!)endAnd this is my attempt:local rooms = {}rooms[1] = {  south=3,  east=2}rooms[2] = {  south=4,  west=1}rooms[3] = {  north=1,  east=4}currentRoom = 1repeat  local move = io.read()  local room = rooms[currentRoom][move]  if room == nil then    room = currentRoom    print(Invalid move)  elseif room == 4 then    print(Congratulations, you won!)  end  currentRoom = room or currentRoomuntil currentRoom == 4 The above code is working but I was wondering if there is something I need to change to improve it somehow.
Simple maze game with four rooms
lua;adventure game
I think overall is good, some bits can be improved but it depends on taste. Take the following comments as suggestions.As rooms is an array, can be defined in a shorter way as:local rooms = {   { south=3, east=2 },   { south=4, west=1 },   { north=1, east=4 },}Variable currentRoom can be localized:local currentRoom = 1In Lua can compare a var to nil or ask not var:if not room then   ...endBranches are exclusive, use of elseif can be skipped:if not room then   room = currentRoom   print(Invalid move)endif room == 4 then   print(Congratulations, you won!)endEDIT:I would rearrange the code at the bottom as:-- Update room state.room = rooms[currentRoom][move]if room then  currentRoom = roomelse  print(Invalid move)end-- Reached final state?if currentRoom == 4 then  print(Congratulations, you won!)endthat avoids the currentRoom = room or currentRoom statement (currentRoom only gets updated is room is not nil).