What will be the output of the following code segment in Lua

What will be the output of the following code segment in Lua?

x = 1

y = 3

do

local x = x

print(x)

x = x+y

do

local y = 5

local x = x+y

print(x)

end

print(x)

end

print(x)

Solution

According to the flow of given instructions after the execution the output will be

1

9

4

1

What will be the output of the following code segment in Lua? x = 1 y = 3 do local x = x print(x) x = x+y do local y = 5 local x = x+y print(x) end print(x) end

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site