Understanding the browser function debugging

Hi, I am trying to understand how the browser function works,
In particular I am confused with regard to the browser command next as it seems to me that it has a weird behaviour,
If you look at my example below you can see that when I tried to run the fourth iteration it returned the same results of the third iteration again, meaning that it did not run the next step,

I am naive about the browser function and I would like to understand more,
Any help is really appreciated

> numbers<-seq(1:100)
> cumsum(numbers)
  [1]    1    3    6   10   15   21   28   36   45   55   66   78   91  105  120  136  153
 [18]  171  190  210  231  253  276  300  325  351  378  406  435  465  496  528  561  595
 [35]  630  666  703  741  780  820  861  903  946  990 1035 1081 1128 1176 1225 1275 1326
 [52] 1378 1431 1485 1540 1596 1653 1711 1770 1830 1891 1953 2016 2080 2145 2211 2278 2346
 [69] 2415 2485 2556 2628 2701 2775 2850 2926 3003 3081 3160 3240 3321 3403 3486 3570 3655
 [86] 3741 3828 3916 4005 4095 4186 4278 4371 4465 4560 4656 4753 4851 4950 5050
> results<-rep(0,100)
> results[1]<-numbers[1]
> for (i in 2:length(numbers)){
+   results[i]<-results[i-1]+ numbers[i]
+   browser()
+ }
Called from: top level 
Browse[1]> i
[1] 2
Browse[1]> n
debug at #2: results[i] <- results[i - 1] + numbers[i]
Browse[1]> results
  [1] 1 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [45] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [89] 0 0 0 0 0 0 0 0 0 0 0 0
Browse[1]> i
[1] 3
Browse[1]> n
debug at #3: browser()
Browse[1]> results
  [1] 1 3 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [45] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [89] 0 0 0 0 0 0 0 0 0 0 0 0
Browse[1]> i
[1] 3
Browse[1]> n
Browse[1]> results
  [1] 1 3 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [45] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
 [89] 0 0 0 0 0 0 0 0 0 0 0 0

you seem to have chosen a pattern of investigation where you typie i then n then results this seems an odd choice to me, as it alternates what you are peeking at the value of as you move from line to line (and browser is now also one of the lines to be navigated) ;
I suggest that if you want to track the change at every line navigating over them via n then it might make more sense to me that you would look at i and results once for each n

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.