Wrong/missing value in STEP-mode for $i++

Things you’d like to miss in the future...
Forum rules
You might want to read this if you're looking for priority service

:info: Please Include The Following Information
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: Use Your Profile Or Signature
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
Post Reply
PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Wrong/missing value in STEP-mode for $i++

Post 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.

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Re: Wrong/missing value in STEP-mode for $i++

Post 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.

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Wrong/missing value in STEP-mode for $i++

Post 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:

Code: Select all

incr
$i

1
I wonder why the 3rd line is empty?

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Wrong/missing value in STEP-mode for $i++

Post 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]"
To see the attached files, you need to log into the forum.

admin
Site Admin
Posts: 67340
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Wrong/missing value in STEP-mode for $i++

Post by admin »

I admit it's useful to have the value right in the steps dialog, and it was easy, so I did it. :)

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Wrong/missing value in STEP-mode for $i++

Post 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? :roll: ) 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? 8)

admin
Site Admin
Posts: 67340
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Wrong/missing value in STEP-mode for $i++

Post 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? 8)
I wanted to do this all the time. Finally did it. 8)

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Wrong/missing value in STEP-mode for $i++

Post 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? 8)
I wanted to do this all the time. Finally did it. 8)
:D No, yes??? :D

...waiting for the next beta
...waiting for the next
...waiting for the
...waiting for
...waiting
...waitin
...waiti
...wait
...wai
...wa
...w
...

Sorry :oops:

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Wrong/missing value in STEP-mode for $i++

Post by PeterH »

admin wrote:I wanted to do this all the time. Finally did it. 8)
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!!

Post Reply