| View previous topic :: View next topic |
| Author |
Message |
Walker Guest
|
Posted: Wed Dec 10, 2003 2:06 pm Post subject: Continue ? |
|
|
In an application I have now for the first time tried using the Continue
statement.
It seems, however, I get some backwards results.
for LoopPar:=1 to 100 do
begin
<something>
if LoopPar and 1>1 then
Continue;
<something else>
end;
When is <something else> supposed to be processed ?
If LoopPar is odd or if it is even ?
|
|
| Back to top |
|
 |
René Larsen Guest
|
Posted: Wed Dec 10, 2003 6:55 pm Post subject: Re: Continue ? |
|
|
In article <3FD72849.F886A36C (AT) sol (DOT) dk>, Walker wrote:
| Quote: |
In an application I have now for the first time tried using the Continue
statement.
It seems, however, I get some backwards results.
for LoopPar:=1 to 100 do
begin
something
if LoopPar and 1>1 then
Continue;
|
"LoopPar and 1>1" is the same as "(LoopPar and 1)>1". The expression
"LoopPar and 1" returns 0 or 1, neither of which can ever be >1.
It should be replaced with:
if (LoopPar and 1) = 1 then // odd?
or:
if (LoopPar and 1) = 0 then // even?
You could also use the Mod() function:
if (LoopPar mod 2) = 1 then // odd?
if (LoopPar mod 2) = 0 then // even?
Hope this helps.
Regards, René
|
|
| Back to top |
|
 |
Jud McCranie Guest
|
Posted: Wed Dec 10, 2003 6:56 pm Post subject: Re: Continue ? |
|
|
On Wed, 10 Dec 2003 19:55:06 +0100, René Larsen
<rene.larsen (AT) spamfilter (DOT) dk> wrote:
| Quote: | "LoopPar and 1>1" is the same as "(LoopPar and 1)>1". The expression
"LoopPar and 1" returns 0 or 1, neither of which can ever be >1.
It should be replaced with:
if (LoopPar and 1) = 1 then // odd?
or:
if (LoopPar and 1) = 0 then // even?
You could also use the Mod() function:
if (LoopPar mod 2) = 1 then // odd?
if (LoopPar mod 2) = 0 then // even?
|
or better:
if odd( LoopPar) then ...
or
if not odd( LoopPar) then ...
|
|
| Back to top |
|
 |
Rob Kennedy Guest
|
Posted: Wed Dec 10, 2003 7:52 pm Post subject: Re: Continue ? |
|
|
Jamie wrote:
| Quote: | if Boolean(LoopPar and 1) then...
|
Please do not type cast numeric expressions to Boolean. It doesn't
always work as you might expect. It relies on the knowledge -- it
assumes -- that the Boolean values of True and False are stored
internally with byte values of $01 and $00, respectively.
--
Rob
|
|
| Back to top |
|
 |
Jamie Guest
|
Posted: Wed Dec 10, 2003 10:38 pm Post subject: Re: Continue ? |
|
|
u r not correctly setting the loop for the AND section.
there are a couple of ways.
if loopPar and 1 <> 0 then.
or
if Boolean(LoopPar and 1) then...
Walker wrote:
| Quote: | In an application I have now for the first time tried using the Continue
statement.
It seems, however, I get some backwards results.
for LoopPar:=1 to 100 do
begin
something
if LoopPar and 1>1 then
Continue;
something else
end;
When is <something else> supposed to be processed ?
If LoopPar is odd or if it is even ?
|
|
|
| Back to top |
|
 |
|