Page 1 of 1
Wrong/missing value in STEP-mode for $i++
Posted: 22 Jan 2012 11:06
by PeterH
For debug purpose I run a script in step-mode. So for every set command the (new) value to be set is shown: OK.
But this does not happen with the increment-command "++", for example see this script:
Code: Select all
STEP;
$i = 0;
While ($i < 5) {
$i++; // debug shows always 1
$j = $i; // debug OK: 1, 2, 3, 4 or 5
}
For the $j=$i; you see the correct value is being set.
For $i++ you always see a 1, maybe the value to increment with. But you never see the result, i.e. 1, 2, 3, 4 or 5.
If debugging a big loop, maybe with stepping started on some condition after several loop-executions, it would be very helpful to directly see the incremented value, without the need to open the Variables-window and searching for the variable name.
Re: Wrong/missing value in STEP-mode for $i++
Posted: 22 Jan 2012 18:42
by serendipity
I don't think there is anything wrong or missing when using $i++. Like you mentioned, it just shows what the increment value is. You could always use $i=$i+1 for what you want to achieve.
Re: Wrong/missing value in STEP-mode for $i++
Posted: 23 Jan 2012 11:40
by PeterH
serendipity wrote:I don't think there is anything wrong or missing when using $i++. Like you mentioned, it just shows what the increment value is. You could always use $i=$i+1 for what you want to achieve.
Sorry: I just don't understand.
Do you think that, when debugging a command for incrementing some value by one, it is better to display that the increment is one, instead of displaying that the result is 387?
(Meaning that you are surprised by the info that your loop-counter is incremented by one, instead of seeing that this is the 387th pass through the loop?)
You can't mean that, do you?
I'm convinced that, just like for a set operation (i.e. $i = ...; ), the result should be displayed, not the information, that for increment.by.1 the increment is 1.
Further a bit strange: the display when stepping a $i++; is:
I wonder why the 3rd line is empty?
Re: Wrong/missing value in STEP-mode for $i++
Posted: 23 Jan 2012 12:23
by Stefan
I too think there is nothing wrong in the debug dialog.
The info about the increment value is also needed.
I agree, the new value could be better displayed then in an separate dialog ([Variables...])
I would also like an third panel which shows the values always instead the need to opening an new dialog, but...
WatchVars.png
But your work around "$j = $i; " seems pretty nifty and works. Good idea.
PeterH wrote:I wonder why the 3rd line is empty?
The syntax "$var++" is new,
before there was and still is the old syntax "incr outputvar, [value], [increment=1]"
Re: Wrong/missing value in STEP-mode for $i++
Posted: 23 Jan 2012 12:34
by admin
I admit it's useful to have the value right in the steps dialog, and it was easy, so I did it.

Re: Wrong/missing value in STEP-mode for $i++
Posted: 23 Jan 2012 14:45
by PeterH
admin wrote:I admit it's useful to have the value right in the steps dialog, and it was easy, so I did it.

Ahh - fine!
I'm a bit surprised that the not-incremented value is shown, but not the incremented result. But as it's together with the increment (was it 1?

) it fits there.
Many thanks - it's really helpful!
By the way: I still would love if $n++ would return it's value, and as such could be used as an operand, as in
Code: Select all
$n = 0;
while ($n < $lines) {
$name = gettoken($list, $n++, "<crlf>");
...
(...assuming $n++ would return the incremented value.)
I have such constructs again and again - this would always save one line and as such make scripts a bit better readable.
Maybe in Scripting 3.0?

Re: Wrong/missing value in STEP-mode for $i++
Posted: 23 Jan 2012 15:39
by admin
PeterH wrote:I have such constructs again and again - this would always save one line and as such make scripts a bit better readable.
Maybe in Scripting 3.0?

I wanted to do this all the time. Finally did it.

Re: Wrong/missing value in STEP-mode for $i++
Posted: 23 Jan 2012 15:54
by PeterH
admin wrote:PeterH wrote:I have such constructs again and again - this would always save one line and as such make scripts a bit better readable.
Maybe in Scripting 3.0?

I wanted to do this all the time. Finally did it.

No, yes???
...waiting for the next beta
...waiting for the next
...waiting for the
...waiting for
...waiting
...waitin
...waiti
...wait
...wai
...wa
...w
...
Sorry

Re: Wrong/missing value in STEP-mode for $i++
Posted: 23 Jan 2012 21:02
by PeterH
admin wrote:I wanted to do this all the time. Finally did it.

Very big success here!!!
OK: first I had to realize that sometimes using it can make the code look bad. But only sometimes!
So I changed it where it looked logical. (In the moment only situations where the incremented variable appears as an operand in a function, like:
$lf1 = GetToken($tf1, $nf1++, "<crlf>");
==> Result: worked OK!
Had a look at the rest: there were constructs like:
Code: Select all
$cnt = 0; // to limit loop on error or bad data
$lim = 10; // the limit
While ($cnt <= $lim) {
$cnt++;
...
IF (...) {break}
...
}
Here the $cnt is only to limit the execution of the loop - but is never referenced. So no chance to inline-increment? One moment: changed that to:
Code: Select all
$cnt = 0; // to limit loop on error or bad data
$lim = 10; // the limit
While ($cnt++ <= $lim) {
...
IF (...) {break}
...
}
...and it works! Is this intentional?? However: it is
very good!!!
So I'm more than fully satisfied with this change!
Thanks!!