简体   繁体   中英

How do you stop a program from running in a blueprint class using a nested if statement and not a System.exit(0);?

In this code I tried to stop the program from running by using System.exit(0);

Is there a possible way to exit the program using a nested if statement and not using System.exit(0);

public String answerR1()
{
    if (answer .equals ("snow"))
    {
        message = "\nCorrect!";
    }
    else
    {
        message = "\nIncorrect!";
        System.exit(0);
    }
    return message;
}
public String answerR2()
{
    answer = answer.toLowerCase();
    if (answer .equals ("time"))
    {
        message = "\nCorrect!";
    }
    else
    {
        message = "\nIncorrect!";
        System.exit(0);
    }
    return message;
}
public String answerR3()
{
    if (answers == 20)
    {
        message = "\nCorrect!";
    }
    else
    {
        message = "\nIncorrect!";
        System.exit(0);
    }
    return message;
}
    public String answerR1()
{
    if (answer .equals ("snow"))
    {
        message = "\nCorrect!";
    }
    else
    {
        message = "\nIncorrect!";
        //System.exit(0);
        break;
    }
    return message;
}
public String answerR2()
{
    answer = answer.toLowerCase();
    if (answer .equals ("time"))
    {
        message = "\nCorrect!";
    }
    else
    {
        message = "\nIncorrect!";
        //System.exit(0);
        break;
    }
    return message;
}
public String answerR3()
{
    if (answers == 20)
    {
        message = "\nCorrect!";
    }
    else
    {
        message = "\nIncorrect!";
        //System.exit(0);
        break;
    }
    return message;
}

Try to use Break instead of System.exit(0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM