BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 1:11 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Can not have While...Wend inside Do...While
PostPosted: Wed Jul 07, 2010 4:09 pm 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 527
This is more of a FYI and probably by design. I knew that you could not directly have these two constructs nested, as coding something like this:
Code:
do
    while zzz
    wend
while yyy

Could be confusing/ambiguous to the compiler. But today I ran into it when the loops were contained within a If...endif which should have removed all ambiguity... Something like:
Code:
i   var   byte
j   var byte

i = 0
j = 0
do
   if j < 50 then
      while j < i
         j = j + 1
      wend
   endif
   
   i = i + 1
while i < 100

But if you compile this you end up with an error
Code:
Error: FILE C:\USERS\KURT\DESKTOP\LYNXMOTION\XXX.BAS(LINE 8) : [TOKEN WHILE] : IF without ENDIF

On the whle j < i line.

Yes the code above is meaningess. I worked around in the real code...

Kurt


Top
 Profile  
 
 Post subject: Re: Can not have While...Wend inside Do...While
PostPosted: Thu Jul 08, 2010 10:58 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Its not so much by design but an impossible situation. If you have a do...while and you put a while...wend inside of it how can the compiler tell the different between the while of the while...wend and the while of the do...while. Correct, it can't. So if you do this it will think the first while it sees is the end of the do while and then will error out because it gets a wend without a while. :)

Note it doesn't matter what other code is around the while...wend the ambiguity still exists. They are processed in a recursive function. Once you get a do it goes recusive. When it sees a wend(even inside another block like if...then it's going to exit that level of the recursive function, which in this case causes the if without endif situation. All code blocks go recursive. So if you enter a new level bevause of an if and then exit that level because of the while you break the if...then. If you enter the level because of the do and then exit becuase of the while in the while...wend you break the while/wend. I've thought about changing the do...while to a do...loop but that would break old code so I've refrained from doing it. Instead of the do...while you can use the repeat..until with an inverted condition and get the same functionality without breaking nested while...wends.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Can not have While...Wend inside Do...While
PostPosted: Thu Jul 08, 2010 11:46 am 
Offline
Master

Joined: Tue Jun 22, 2010 1:15 pm
Posts: 203
I know, add curly brackets!

Alan KM6VV

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/


Top
 Profile  
 
 Post subject: Re: Can not have While...Wend inside Do...While
PostPosted: Mon Jul 12, 2010 8:37 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Then we'd be using C. :)

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO