0
I have a for
running and clicking on the button I want this for
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’m sending you value like String
when he finds the word "to" he comes out of the for
, put a guy boolean Stop
when true it would come out of the loop too, I change the value by pressing a button but it didn’t work.
I wish you could get out for
saw a button or if there would be another way to do it.
You want, for example, if a condition is false out of the loop?
– Matheus Ribeiro
It would not be the case to use the command
break
?– gato
In the title of your question says one thing and in the body says another. I suggest you make it clearer.
– gato
There is no stopping the execution of a cycle
for
at the click of a button. This is because the interruption would have to be done inside thefor
. And the onClick of the button usually stays out of the loop... Maybe it would be better if you told what you want to do. What is the cycle for?– Rosário Pereira Fernandes
Let me guess, the thread running this
for
is the same one that should notice the click of the button. I got it right? Because if that is so, you would have to have the same thread running two lines simultaneously, which you can’t do since a thread is by definition a line of execution. The solution would be to run this yoursfor
within a separate thread.– Victor Stafusa
@Victorstafusa had thought about it but hadn’t tested it, tested it as a new thread and it worked, thanks.
– Vale