BACK-TO-BACK level lua

On level ‘Back to back’ in forest I get ReferenceError: enemy is not defined when my code looks like:

while true do
    enemy = hero:findNearestEnemy()
    if enemy then
        hero:attack(enemy)
        hero:attack(enemy)
    else
        hero:moveXY(40, 34)
    end
end

@szymex73

It should be:

local enemy = hero:findNearestEnemy()