WHILE/WEND stability issues
issueid=325 22-10-2011 17:11
Super Moderator
Number of reported issues by Petr Schreiber: 131
WHILE/WEND stability issues
WHILE/WEND seems to crash under certain circumstancies

Hi Eros,

I found out WHILE/WEND sometimes crashes once executing the condition.

Crashing (nonsense) code 1:
Uses "Console"

Dim MyValues(10) As Long

Long n, nOld

For n = 1 To UBound(MyValues)
  MyValues(n) = 1
    
  If n > 1 Then
  
    For nOld = 1 To n-1
    
      While (MyValues(n) = 1)        
        MyValues(n) = 2
      Wend                          
      
    Next
  
  End If
    
Next

WaitKey
Crashing (nonsense) code 2:
Uses "Console"

Long i

For i = 1 To 2
  While 1     
    PrintL "Endless loop, I like it!"    
  Wend
Next         

WaitKey
In both cases I get GPF.


Petr
Issue Details
Issue Number 325
Project thinBasic
Category Core engine (thinCore.dll)
Status Fixed
Priority 1 - Highest
Affected Version 1.8.9
Fixed Version 1.9.1
Milestone thinBasic 1.9.0.0
Users able to reproduce bug 0
Users unable to reproduce bug 0
Assigned Users (none)
Tags (none)




22-10-2011 21:07
Super Moderator
It seems the problem occurs only in case the WHILE/WEND is inside FOR/NEXT.


Petr

24-10-2011 21:55
thinBasic author
Petr, I found it.
It is quite dummy and should be easy to fix.
Problem is related to the fact that FOR construct in thinBasic is quite complex and it supports also WHILE or UNTIL clause at the end.
See syntax at http://www.thinbasic.com/public/prod...ml?fornext.htm
FOR Counter [ AS AnyNumericType] = nStart TO nStop [STEP Increment] [{WHILE | UNTIL} LogicalExpression]
 ...
 {statements}
 [EXIT FOR]
 [ITERATE FOR]
 {statements}
 ...
NEXT [Counter]
So a WHILE after a FOR ... statement is interpreted as a FOR ... continuation

You can try adding a statement after your FOR ... line and you will see what I mean.
The following will be OK:
Uses "Console"

Long i

For i = 1 To 2
i = i      '<<<<<<<<<<<<<<<<<Add this code and all will work fine
  While 1**** 
    PrintL "Endless loop, I like it!"***
  Wend
Next

WaitKey
OK, Now I've identified the problem but I need to find a solution.
I suppose the solution is to test if there is a END of LINE or not.

Ciao
Eros

24-10-2011 23:25
thinBasic author
I think I've fixed this one.
Fix will be present in next release.

+ Reply