Author Topic: [fixed]A my first Debug session on FOR NEXT issue  (Read 3211 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
[fixed]A my first Debug session on FOR NEXT issue
« on: November 05, 2021, 11:16:55 pm »
Hi QB64 Community
Hi Qb64 developers Team

just to keep in live my toon character
I share with you this my experience got during Recursive session!
I fall on a simple FOR NEXT STEP loop!
Yes the easiest loop that we have to work repeating a block of instructions.

enviroment:
On Windows 8.1 Pro 64 bit, a HP notebook machine with Celeron 2.0 GHz and using QB64 2.0.1

the goal of the code:
change the STEP value of FOR NEXT loop to change the results of looping

the result of the code:
changing at some point of the loop the Stepper variable the FOR loop goes on with no change of output results.

tool of investigation:
Debug mode of QB64 v2.0.1

here code that shows the issue
Code: QB64: [Select]
  1. StartIndex = 2: stepperIndex = 2: DoneIndex = 20
  2. Print "StepperIndex is 2 but when index will be 18 it becomes -2"
  3. Print " so we expect to see index to decrement after 18 towards negative digits"
  4. For index = StartIndex To DoneIndex Step stepperIndex
  5.     Print index; "->"; index ^ 2;
  6.     _Delay .1
  7.     If index = 18 Then stepperIndex = -2 '<------------------------newline
  8.  
  9. Print "another try: the variable a grows up to 100 step 10 until"
  10. Print " it becomes 50, after this variable a should decrease step -10"
  11. a = 1: b = 100: c = 10
  12. For a = 1 To b Step c
  13.     Print a; " ";
  14.     If a = 50 Then c = -c
  15.  


here screenshots
  [ You are not allowed to view this attachment ]  
  [ You are not allowed to view this attachment ]  
  [ You are not allowed to view this attachment ]  
  [ You are not allowed to view this attachment ]  

who can test this issue?
Feedbacks ?
« Last Edit: November 07, 2021, 11:46:53 am by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: A my first Debug session on FOR NEXT issue
« Reply #1 on: November 06, 2021, 12:39:59 am »
First of all this
Code: QB64: [Select]
  1. a = 1: b = 100: c = 10
  2. For a = 1 To b Step c
  3.     Print a; " ";
  4.     If a = 50 Then c = -c
  5.  
is never going to get a = 50, a = 51 but not a = 50

2nd you can't change For loop line values after execution of it has started, only the variable that is the index.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: A my first Debug session on FOR NEXT issue
« Reply #2 on: November 06, 2021, 04:22:08 am »
@TempodiBasic

If you really need to change the loop step somewhere in the program, use DO LOOP as in the following program.

Code: QB64: [Select]
  1. a = 0: b = 100: c = 10
  2. DO UNTIL a = b
  3.     PRINT a;
  4.     IF ABS(a) = 50 THEN c = -c
  5.     a = a + c
  6.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: A my first Debug session on FOR NEXT issue
« Reply #3 on: November 07, 2021, 04:32:16 am »
Hi boys
so LOL I was in trance when I have written this post , last night!
my mind (memory) said me that StepValue can be changed into FOR loop, so I have spent a good part of time to be sure
that the code was breaking this rule and then I have made my  reportage screenshots.
If I had had less believeing in memory, going on this wikipage  https://www.qb64.org/wiki/FOR...NEXTI have had got the truth quickly!

Well, let's see what I got back of positive from this experience:
1.  QB64 community is fantastic, I got feedback from to friends to enlight my obscure state of my mind
      thanks to Bplus for debugging, and thanks to Petr for show me the solution to get the goal.
2.  QB64 wikipage of FOR is very explicative
3.  I must follow the mom's advice to go sleep when it is at some time
4.  The Debug mode works properly and it is fine, moreover its layout is very simple and good.

A special thank to Bplus and Petr.



Programming isn't difficult, only it's  consuming time and coffee