Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
For..Next
#1
I don't think there is present option whereby the NEXT (as in the FOR..NEXT) will automatically display the control variable after Next?? When a For is typed you get an automatic warning that you need the NEXT but if the For already has a control variable then could the warning also include the control variable? For x = 1 to 10 "Warning missing NEXT x"

I do appreciate there is a lot less typing if the control variable is not needed to complete the For .. Next but sometimes when I have a lot of nested IF statements with a lot of For..Next loops it is always a missing End If that is somewhere in that mess of code which creates a Program Flow error. Following which For goes to which Next can be a little challenging. So I was thinking is the Flow Error highlighted Next x as the loop where I can find the missing End If (as opposed to the Next y or Next Num etc in the same mess of coding) it could help.
Reply
#2
I think you perhaps have too much faith in our developers.  Our ability to generate and make an intellegent AI for the IDE isn't the same as what you'll find elsewhere where some company lie Microsoft can spend millions in paying whole teams of programmers to work on features.  Big Grin

Consider the way a lot of folks program, and then consider this scenario

FOR x = 0 TO _WIDTH
      PSET (x, y), foo


Now, here it'd make sense that there could only be an error for   FOR... WITHOUT NEXT.... FOR x.

But, let's keep typing a little more:

FOR x = 0 TO _WIDTH
    PSET (x,y) , foo
NEXT
PRINT "Hello World"

Error gone!  Life is good!


But now the user goes up and adds a new line of code:

FOR x = 0 TO _WIDTH
    FOR y = 0 TO _HEIGHT
        PSET (x,y), foo
    NEXT
    PRINT "Hello World"

Now, which NEXT is actually missing here?   They didn't write the code with NEXT x explicitly defined when they wrote that first FOR...NEXT previously.  Is it the x which is now left dangling without a NEXT?   Or is it the y, since they just inserted it into the code?

What is the user looking to produce at this point??    Is it:

FOR x = 0 TO _WIDTH
    FOR y = 0 TO _HEIGHT
        foo = foo + y
    NEXT
    PSET (x,y), foo
NEXT
PRINT "Hello World"


If so, then it was the y which was missing the NEXT.


OR were they writing something like this:

FOR x = 0 TO _WIDTH
    FOR y = 0 TO _HEIGHT
        PSET (x,y), foo
    NEXT
    PRINT "Hello World"
NEXT


If so, then it's the x which is missing the NEXT instead!



Personally, I wouldn't have a clue as to hazard a guess at which the end user might end up actually deciding they're wanting to use in their program -- but I have a feeling we'd just annoy a lot of folks if we said, "FOR... WITHOUT NEXT... FOR x", and we got it wrong and it was really their Y which didn't have that NEXT associated with it.

I can just see the post on the forums now:   "You dummies!! I just spent 327 hours trying to debug my code to find where my FOR Y loop was missing a NEXT, and it wasn't!!  I want my money back!!!   This is a total waste!!!  ARRAAAAGGGHHH!!!!!"

And thus we just keep the generic warning:

FOR.... WITHOUT NEXT....   whichever dang next that might be for ya!   Big Grin
Reply
#3
I'm not sure Steve that the IDE isn't sensing a missing variable for the Nexts' in your examples.

If your code is

 For x = 1 To 10
    Print x



or your code is 

For x = 1 To 10
    Print x
next 1

or your is 

For x = 1 To 10
    locate x+2,10
    Print x
next y

Then in each of these example the warning message is about the control variable. No coding errors or program flow errors pop up, the IDE is sensing the error is in the control variable but doesn't state the name of the actual variable although you would think is would know this from the For statement.

I wasn't sure if it was possible to have an option to have the "Next "display the control variable which I thought it already knew, I didn't mean to advocate any major change in the warning message.
Reply
#4
Could the system maybe, when doing its pre-check of the code, be made to add the variable name to the last opened loop?
If I wrote For x=1 to 10 : Print x: Next could it "see" the loop and add the last loop variable name to the Next?
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#5
@Dimster - Is this what you're talking about?

[Image: Screenshot-2024-05-18-001553.png]

IMO this is just a bug, it should say something like `Expected End If but found Next`, that's more accurate to what's actually wrong. This one as well is pretty obviously a bug:

[Image: Screenshot-2024-05-18-001331.png]

"PROGRAM FLOW ERROR!" shouldn't be a thing Big Grin  It should just tell you what ending control statement it was expecting to find vs what it actually found (matched with the line opening the control structure that's incorrectly closed). That would at least tell you what's wrong and where to look.
Reply
#6
Yes DSMan the error warning is sometimes unhelpful in finding where the problems is and it would seem the IDE would already have the various clues to help for quicker detection of where to go in your code to fix the offence. Here is an example :

Code: (Select All)
For x = 1 To 5
    If x + 1 = 3 Then
        Print "Still within the x loop"
        Print "Loop is 1 to 5, loop variable x presently is "; x + 1
        For m = x + 1 To x + 4
            If x + 1 = 5 Then
                Print "At the end of the x loop"
                Print "The next x value will be 6 so none of this will be printer"

                For y = 1 To 3
                    Print "Value of y is now "; y
                Next
                For z = 1 To 4
                    Print "Value of z is now "; z
                Next
Next

So here if the error warning highlights that last NEXT but that NEXT is not the problem. There are 2 problems in this code. The NEXT associated with the FOR M loop is missing. I'm thinking the IDE here in this example is warning of a missing NEXT "m" and not a NEXT "x" which it is highlighting. 

It's either that or the IDE is running through the code top to bottom and the first error it's finding is that "IF x+1=5" condition does not have an END IF. Which I believe is exactly what you are pointing out. It would be great if the warning was as you laid out "Expected an END IF but found a NEXT"

What I was thinking was if the IDE could complete the control variables (ie Next y, Next z, Next x) if there is an error in the code then its a little easier to see a missing Next m,. And if there are no missing Next variables, then the issue has to be a missing END IF or End Select etc.

So great to have a forum you bounce these crazy ideas off of.
Reply
#7
@Dimster, there were too many grammatical errors in it, so the IDE had problems.

It's now grammatically correct, but the output is confused.
Code: (Select All)

For x = 1 To 5
  If x + 1 = 3 Then
    Print "Still within the x loop"
    Print "Loop is 1 to 5, loop variable x presently is "; x + 1
    For m = x + 1 To x + 4
      If x + 1 = 5 Then
        Print "At the end of the x loop"
        Print "The next x value will be 6 so none of this will be printer"

        For y = 1 To 3
          Print "Value of y is now "; y
        Next
        For z = 1 To 4
          Print "Value of z is now "; z
        Next
      End If
    Next
  End If
Next

[Image: Wirrwarr2024-05-18.jpg]
Reply




Users browsing this thread: 1 Guest(s)