lundi 13 juillet 2020

Java : if condition : using a variable inside the if as a condition of the if

As a beginner, I'm trying to code something like that. For sure, the wrong way, because it doesn't work at all. What I'm trying to do is : use the results i can get when I do something inside a if loop and use these results to calculate conditions the next time I enter the if... To be more understanable, I want to do the same thing if cond1 && cond2 are TRUE but not to early even if the situation occurs (delay of 1000) and not at a value under the previous one...

I don't know how to code this, for the first time I enter the if and for the others... Can you help me please??? Thanks a lot.

boolean cond_1 = a < 10;
boolean cond_2 = b < 15;
boolean cond_delay = (time_now - time_i_have_done_something) > 1000;
boolean cond_value = value_now > value_i_have_done_something;

if (cond_A1 == true && cond_A2 == true && cond_delay == true) {
 do something;
 long time_i_have_done_something = do_something.gettime();
 double value_i_have_done_something = do_something.getvalue();
}

Aucun commentaire:

Enregistrer un commentaire