zizi21
asked on
if else continue
hi,
this is stupid question..i know but i dont know how to do it..could you pls help....
for instance,
if(i>0)
value+=1;
else if(i<0)
value=value;
now instead of putting value=value, is there such thing as continue that we use in while looopp...
this is stupid question..i know but i dont know how to do it..could you pls help....
for instance,
if(i>0)
value+=1;
else if(i<0)
value=value;
now instead of putting value=value, is there such thing as continue that we use in while looopp...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry for any repeat info posted by sunnycoder. I'm a slow typist.
np mr_egyptian :)
ASKER
sorry...i was lazy typing everything...
i have this long if else statements where it needs to evaluate
if the first if statement is true do this
otherwise do nothing....
not the real thing but something like this
if(expr1 > 0)
do this...maybe add the value by one or somehting like that
else
do not add the value but just let the value remain...
i have this long if else statements where it needs to evaluate
if the first if statement is true do this
otherwise do nothing....
not the real thing but something like this
if(expr1 > 0)
do this...maybe add the value by one or somehting like that
else
do not add the value but just let the value remain...
then just omit the last 2 lines as figroc had suggested.
Are you looking to code this construct just to make the code self documenting? If so then just make the else part a non-operation with a comment, but make sure you use braces, otherwise the compiler will take the very next line and assume it is part of the else.
As an aside, value=value is almost certainly going to be optimized away by the compiler to be a no-op.
As an aside, value=value is almost certainly going to be optimized away by the compiler to be a no-op.
if(predicate)
{
++value; // Pre-increment is a better bet than += 1
}
else
{
// We take no action in this case (you MUST use braces to encapsulate this comment)
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
C++ sintax doesn't necesarily need an else statement.
The code:
if(i>0)
value+=1;
Does everything you want:
if i is bigger than 0 then augments the variable value with one,
otherwise it remains unmodified.
No need for more instructions.
The code:
if(i>0)
value+=1;
Does everything you want:
if i is bigger than 0 then augments the variable value with one,
otherwise it remains unmodified.
No need for more instructions.
@sistemu, I'm sure if you read this thread carefully you'll see that point has already been made -- more than once!
ASKER
just saw this...pls give me some time to read...
I've just explained it with more English and less IT :D
That's all :)
That's all :)
>> I've just explained it with more English and less IT :D
>> That's all :)
Why would that be necessary? This is an IT thread! If ziz21 needed clarification I'm sure he (or she) is more than capable of requesting it.
>> That's all :)
Why would that be necessary? This is an IT thread! If ziz21 needed clarification I'm sure he (or she) is more than capable of requesting it.
ASKER
thanks