Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i skip a section of code lua?

Tags:

lua

It is my first lua project and i have a trouble with skipping part of my code. I want the code to stop after part "Cool". So if i write good and it answers cool i want the rest of the code to stop since after that the next question is not relative anymore.

How it works: Code says: Hello You say: anything Code says: How are you? You say: good after you say good it will say cool. If you say anything other than good it will ask "Why?" e.g. you say: bad Code says: It will be alright I want it to stop after "cool" and skip out the further part of the code.

os.execute(" cls ")
print("Hello")
    odp = io.read()
        if odp == string then
        end
        tof = true or false

print("How are you?")
    odp2 = io.read()
        if odp2 == "good" then print("Cool") tof = true
            else print("Why?") tof = false
            if tof == true then os.execute(" pause ")   
        end
            end

    odp3 = io.read()
        if odp3 ~= math then print("It will be alright")
            print("Okay, I have to go see you.")
        end
os.execute(" pause ")
like image 865
user3693008 Avatar asked Jan 25 '26 01:01

user3693008


1 Answers

When you compile code, it becomes the body of a function. The prototypical way of exiting a function is with a return statement. A function can have zero or more return statements.

But, since you want to exit the program, you can instead call os.exit().

like image 199
Tom Blodget Avatar answered Jan 26 '26 19:01

Tom Blodget