if

A

ahso

Hi
I only want either first or second if but not both executed. ie. if
value 1 do not execute 2 even if 2nd value ==1 but also if 2nd do not
execute first if.
Thanks


if (R22value == 1){
DreiDimensional = 0;
function();
}

if (R23value == 1){
DreiDimensional = 1;
function();
}
 
I

Ian Collins

Hi
I only want either first or second if but not both executed. ie. if
value 1 do not execute 2 even if 2nd value ==1 but also if 2nd do not
execute first if.

That requirement contradicts its self.
 
F

Fred Zwarts \(KVI\)

"ahso" wrote in message
Hi
I only want either first or second if but not both executed. ie. if
value 1 do not execute 2 even if 2nd value ==1 but also if 2nd do not
execute first if.
Thanks


if (R22value == 1){
DreiDimensional = 0;
function();
}

if (R23value == 1){
DreiDimensional = 1;
function();
}

It is not clear to me what you mean. As I read it, the obvious solution is:

if (R22value == 1){
DreiDimensional = 0;
function();

} else if (R23value == 1){
DreiDimensional = 1;
function();
}
 
A

ahso

The problem is that either value can be 1. I only want to avoid
running both simultanoulsy. I tried with setting within each if the
other value to 0 but
that's not working. I probably need to do as Fred so users have to
click the first value to disable then click the second.
 
F

Fred Zwarts \(KVI\)

"ahso" wrote in message
The problem is that either value can be 1. I only want to avoid
running both simultanoulsy. I tried with setting within each if the
other value to 0 but
that's not working. I probably need to do as Fred so users have to
click the first value to disable then click the second.

What are types of R22value, R23value and DrieDimensional?
You use them as integer-like variables, what are their expected values?
You seem to use only the values 0 and 1, maybe you should use bool type.
It is still not clear to me what you want to do.
Maybe you could explicitly program the four cases,
which would make your intention more clear.
What do you want to do in the other two cases?

if (R22value == 1 ){
if (R23value == 1){
// R22value == 1, R23value == 1

throw Inconsistency;????
ComplainToUser ();?????

} else {
// R22value == 1, R23value != 1

DreiDimensional = 0;
function();

}
} else {
if (R23value == 1){
// R22value != 1, R23value == 1

DreiDimensional = 1;
function();

} else {
// R22value != 1, R23value != 1

throw Inconsistency;???????
ComplainToUser ();?????

}
}
 
C

copx

Hi
I only want either first or second if but not both executed. ie. if
value 1 do not execute 2 even if 2nd value ==1 but also if 2nd do not
execute first if.
Thanks


if (R22value == 1){
DreiDimensional = 0;
function();
}

if (R23value == 1){
DreiDimensional = 1;
function();
}

English is not your first language, right? Seriously, your broken
English makes it hard to understand what you actually mean.
I guess you want this:

if (R23value != 1 && R22value == 1){
DreiDimensional = 0;
function();
}

if (R22value != 1 && R23value == 1){
DreiDimensional = 1;
function();
}
 
J

Juha Nieminen

ahso said:
Hi
I only want either first or second if but not both executed. ie. if
value 1 do not execute 2 even if 2nd value ==1 but also if 2nd do not
execute first if.
Thanks


if (R22value == 1){
DreiDimensional = 0;
function();
}

if (R23value == 1){
DreiDimensional = 1;
function();
}

Just put an "else" before the second "if".
 
L

LR

ahso said:
Hi
I only want either first or second if but not both executed. ie. if
value 1 do not execute 2 even if 2nd value ==1 but also if 2nd do not
execute first if.
Thanks


if (R22value == 1){
DreiDimensional = 0;
function();
}

if (R23value == 1){
DreiDimensional = 1;
function();
}


What you want to do isn't entirely clear to me, but perhaps this snippet
will be of use, if only as a point of departure,


void f2(const int R22value, const int R23value) {

std::cout << "(" << R22value << "," << R23value << ") ";

static const int threeDim = 1;
static const int twoDim = 0;
static const int invalidDim = -1;

const bool r2 = R22value != 0;
const bool r3 = R23value != 0;

const std::pair<bool,bool> ab(r2,r3);


const int dim =
ab == std::make_pair(false,true) ? threeDim :
ab == std::make_pair(true,false) ? twoDim :
invalidDim;


if(dim != invalidDim) {
// call function here
std::cout << "It\'s valid, it was " << dim << std::endl;
}
else {
// don't call function here
std::cout << "It was invalid" << std::endl;
}

}
 
A

ahso

Thanks copx. I added after your code (only boolean 0/1 values):

if (R23value == 1 && R22value == 1){
R22value = 0;
R23value = 0;

}

That way users have to double click but ok.
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top