Forums

post while

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

post while

Postby DelphiGuy » Thu Jan 03, 2013 10:24 am

Code: Select all
               post while incrementz == 0
                  incrementz = 1


i'll post more of the surrounding code if need be, but to start with: how on earth can incrementz == 0 after this code runs?

yes, i understand it's goofy do-nothing code. i'm just trying to understand and debug the while loop logic.

my understanding of this fragment is that a value of 1 is first assigned to incrementz. only after that (because of the "post" modifier), incrementz is evaluated to see whether it is equal to 0. since obviously it never can equal 0 (after all, it was just assigned 1), this code should never loop and the while loop is exited.

but to my confusion, after this code executes, incrementz equals 0, not 1.

what's wrong with my thinking, please?
DelphiGuy
 
Posts: 116

Re: post while

Postby Charles » Thu Jan 03, 2013 11:10 am

What do you get for "trace incrementz" before the loop?

I do not get 0 for this program:
class X

def main
print 'start'
post while a == 0
a = 1
trace a
print 'done.'

-->
Code: Select all
start

    trace : a=1
          - at post-while.cobra:7
          - in X.main
done.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: post while

Postby DelphiGuy » Thu Jan 03, 2013 12:55 pm

I'm getting a trace of incrementz, just prior to the loop, of 0. Just subsequent to the loop, trace shows a value of 1. I should have thought of using trace, myself. Didn't think of it, because Monodevelop is showing incrementz to have value of 0, just subsequent to the loop, so I simply trusted that.

Yes, that's correct. MD seems to conflict with its own reporting, depending on whether I look at the trace output in "Application Output" or instead watch the variable's value change in "Locals".

I'll have to bring my attention to this tonight and try to understand how that could be. I assume it's "operator error", but so far I'm not seeing my error.

If I really can't track down the paradox, I'll clean up a code example and post it, though I fear there's not too many MD users on this discussion board at the moment.

Thanks, Charles.

Paul
DelphiGuy
 
Posts: 116

Re: post while

Postby DelphiGuy » Thu Jan 03, 2013 8:28 pm

i am no longer having this problem and really have no idea why MD started behaving this evening. again, i assume the illogic is mine, not MD's, but really not sure.
DelphiGuy
 
Posts: 116


Return to Discussion

Who is online

Users browsing this forum: No registered users and 15 guests