While not executing

That sounds like new behavior. I’ve never seen it do that.

In While, the expression is evaluated upon entry, then execution within the loop is linear.

This shows it very clearly :

dim whi as integer = 1 while whi = 1 system.debuglog "1" whi = 1 system.debuglog "2" exit wend

If, as John says, execution started at Wend, “1” and “2” would never show up.

Urban legends abound…

John’s talking about the steps the debugger takes as you’re stepping through that loop. In your code, if you set a break point at the dim statement, then stepped through, you’d see it go to the while line, then to wend, then back to system.debuglog.

To double-down on this nerdiness, it doesn’t actually go to the While line, just straight to Wend and then back to the first line inside the while statement.

The debugger skips over Do but at least it doesn’t go straight to the Loop Until, it goes to the first statement, as you’d expect.

Similarly, the debugger appears to skip over the Do Until line and it goes to the first statement inside the loop.

A For loop works as you’d expect, showing the debugger go to the For line and then inside the For loop.

Initially I thought that it was skipping the While and Do lines as there’s nothing in there for the debugger to evaluate. But there is something for the debugger to evaluate in Do Until, so that doesn’t explain it. And none of this explains why it goes to Wend first.

(This takes me back to the days I was writing BASIC language interpreters.) The code flow in loops of any kind have to test exit conditions not only at the end the loop but also on loop entry. So with Do and While loops it jumps to the end to test if the entry condition matches or exceeds the exit condition. If not the program pointer returns to the start of the loop and processes the statements until it again reaches the point where the condition testing occurs.

For loops are handled differently since the statement also includes initialization of the loop variable and limits.

Ok, so boiling this all down for simplicity…a For statement is an executable statement; Do and While statements are not in the sense that they don’t really do anything except set limit conditions.

Did that make any sense?

It is new.

The stepping sequence in Xojo 13r4.1 lands on while, not wend, but reversed by 14r3.0. Do loops step the same.

[code]break //0

dim i As integer //1

while i < 3 //2

i = i + 1 //3

wend //4

beep //5

13r4.1: 0, 1, 2, 3, 2, 3, 2, 3, 2, 5, end sub

14r3.0: 0, 1, 4, 3, 4, 3, 4, 3, 4, 5, end sub[/code]

You are right. It does step to wend before going to the first instruction in the loop. But for all intents and purpose, it does not change anything as far as practical execution of the code is concerned.

Interesting old thread…I just ran into this myself trying to test code inside a while…but the debugger appeared to be stepping over the code – so I would stop execution and try to figure out why. This seems like really odd behavior in the debugger to me…however now that I’ve seen it… I guess I’ll know next time.

I was sure there was already a bug report about this behaviour but I cant find it in feedback if there is one

<https://xojo.com/issue/57500>