Hello all,

Tried searching the forums for for any mention of .WHILE .DO loops not peforming as they should (I seem to remember a Microsoft tech note about it) but didn't find what I was looking for.

Has anyone else had problems using .WHILE .DO loops when the loop when the condition of the loop consists of an (XXXX==BBB) OR (YYY==FFF) e.g.

.WHILE (ecx < PROFILELENGTH) && (numberOfSamples < NUMBEROFSAMPLES)

execute code

inc ecx
inc numberOfSamples

.ENDW

When I try this loop, it seems to ignore the second (numberOfsamples < NUMBEROFSAMPLES) condition and only end the loop when the first becomes invalid. Anyone else come across this ? It's possible I might have badly coded the loop, I didn't spend alot of time trying to figure out why it wouldn't work, I just used a .REPEAT/.UNTIL, but i should like to know if it's me or a masm bug, (ok.. most likely me !) as the use of .REPEAT.UNTIL is sometimes inappropriate etc etc.

Cheers

Codey
Posted on 2002-12-28 06:41:42 by CodeBug
For OR you should use "||", not "&&" :) . Actually the loop ends if both conditions are false.
Posted on 2002-12-28 09:15:38 by japheth
Japeth,

Thinking about it, I must have got my &&'s and ||'s mixed up. thats what comes when i don't go and get my beauty sleepy

Cheers !

Codebug
Posted on 2002-12-28 10:05:07 by CodeBug
As well, use brackets..

.WHILE ( (ecx < PROFILELENGTH) && (numberOfSamples < NUMBEROFSAMPLES) )

.ENDW

Last thing to remember is that as you have it, the values will be treated as UNSIGNED numbers. A negative signed number is a very LARGE unsigned number, and may be causing faults.

To indicate signed conditions use "SDWORD PTR" (signed-DWORD)

.WHILE ( (SDWORD PTR ecx < PROFILELENGTH) && (SDWORD PTR numberOfSamples < NUMBEROFSAMPLES) )

Hope this helps..
:alright:
NaN
Posted on 2002-12-28 10:07:46 by NaN
Tried messing with the brackets but didn't affect the result stragnely. I think the thing about unsigned words may have possibly been a problem
Posted on 2002-12-28 10:37:27 by CodeBug