How to stop one via external loop interference?

0

I have for running and when I click the button I want this for to stop.

           for (int i = 0; i < codigo.size(); i++) {


            if (codigo.get(i).contains("Para") || Stop == true){

                sendCommand("parou");

                break;

            } else {
                sendCommand(codigo.get(i));

            }

I am typing value type String when it finds the word "To" it exits from for , I put a type boolean Stop when true it would exit the loop too, I change the value by pressing a button but it did not work. I would like how could% quit% go through a button or would have another way to do that.

    
asked by anonymous 28.07.2018 / 16:41

1 answer

1
   boolean keepGoing = true;

    for (int i = 0; i < codigo.size(); i++) {
        if (keepGoing) {
            i++;

        } else {
            return;
        }
    }

    void onClick(view v){
        keepGoing = false;
    }
    
30.07.2018 / 15:05