P
P
Pavel Dmitriev2015-03-09 13:02:07
Java
Pavel Dmitriev, 2015-03-09 13:02:07

How to fulfill all conditions without repeating?

I have 4 conditions that must be met together.

if ( условие 1 ) { оператор 1 } ;
if ( условие 2 ) { оператор 2 } ;
if ( ( условие 1 ) && ( условие 2 ) ) { оператор 1; оператор 2; } ;
if ( ( условие 2 ) && ( условие 1 ) ) { оператор 2; оператор 1; } ;

But in this form, either 1 or 2 condition is duplicated twice and the execution is repeated.
How to combine these conditions so that the execution of statements is not repeated?
Upd.:
I have two buttons that fulfill conditions 1 and 2. When button 1 is pressed, sound 1 sounds, when button 2 is pressed, sound 2 sounds. But the catch is that the buttons can be pressed simultaneously. And how then to determine which sound should sound first, which second? And if pressing a button is milliseconds later, then even just in this case
if (condition 1) { operator 1 } ;
if ( condition 2 ) { statement 2 } ;
duplication occurs and one sound sounds twice.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Saboteur, 2015-03-09
@saboteur_kiev

Your answer is
if ( condition 1 ) { statement 1 } ;
if ( condition 2 ) { statement 2 } ;
All.

V
Vasily, 2015-03-09
@Applez

if ( ( условие 1 ) && ( условие 2 ) ) { оператор 1; оператор 2; } ;
if ( ( условие 2 ) && ( условие 1 ) ) { оператор 2; оператор 1; } ;

this piece, it seems, does not make sense at all, the second will never be executed.

M
Mokhirjon Naimov, 2015-03-09
@zvermafia

In my opinion it should be done like this:

if ( условие 1 && !(( условие 1 ) && ( условие 2 )) ) { оператор 1 } ;
if ( условие 2 && !(( условие 1 ) && ( условие 2 )) ) { оператор 2 } ;
if ( ( условие 1 ) && ( условие 2 ) ) { оператор 1; оператор 2; } ;
if ( ( условие 2 ) && ( условие 1 ) ) { оператор 2; оператор 1; } ;

And so 3-4 conditions as a paradox! :)

P
Pavel Dmitriev, 2015-03-10
@klieve

In general, I made this method of checking and hung it on the buttons. Now it works as it should without additional conditions.

Button playOne, playTwo;
...
playOne = (Button) findViewById(R.id.playOne);
playTwo = (Button) findViewById(R.id.playTwo);
...
public void verification(Button b) {
if (b == playOne) { playSound(sound_one); } 
if (b == playTwo) { playSound(sound_two); }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question