Special variable to read out ||-match

  • Thread starter Bart Van der Donck
  • Start date
B

Bart Van der Donck

Hello,

In this code

if ( 1 == 1
|| 1 == 2
|| 0 == 0
|| 2 == 5 ) {
print "You're here because check 1 and 3 where okay.";
}

Is there a possibility to readout which checks were positive and which
negative in the ||-series ?

Thank you
 
I

it_says_BALLS_on_your_forehead

Bart said:
Hello,

In this code

if ( 1 == 1
|| 1 == 2
|| 0 == 0
|| 2 == 5 ) {
print "You're here because check 1 and 3 where okay.";
}

Is there a possibility to readout which checks were positive and which
negative in the ||-series ?

not in that code. you would short circuit on the first true condition.
if you had separate 'if' statements for each condition, and set a flag
for each condition that was true, with each flag representing a bit,
you could sum the bits together and come up with a decimal
representation of a binary number that represents the 'check numbers'
that were true. so in this case 1 and 3 being true would correspond to:
1010 ( up to you to decide if you want to go left-to-right or
vice-versa). 1010 would equate to 10.
 
B

Bart Van der Donck

it_says_BALLS_on_your_forehead said:
not in that code. you would short circuit on the first true condition.
if you had separate 'if' statements for each condition, and set a flag
for each condition that was true, with each flag representing a bit,
you could sum the bits together and come up with a decimal
representation of a binary number that represents the 'check numbers'
that were true. so in this case 1 and 3 being true would correspond to:
1010 ( up to you to decide if you want to go left-to-right or
vice-versa). 1010 would equate to 10.

Thanks it_says_BALLS_on_your_forehead. I've found a similar workaround.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top