April 24, 2024, 07:37:02 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


unmatched "IF" or "WHILE"

Started by Robert34, June 23, 2011, 05:08:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Robert34

Sometimes I have a missing "endif" or "endwhile" statement.
This may not be flagged until the end of program and it can be very hard to figure out where the problem is.

Is there an option to flag the error as soon as it's detected, like at the end of a Subroutine?
The if and while statements don't extend past an EndSub statement.
If there is a counter keeping track of open if statements, it should be back to zero when the EndSub statement is encountered.

Thanks.

-- Robert

sapero

Hi Robert,
Only the IF stack is checked at ENDSUB - it must be empty (currently).
I'll add more checks for the other x-endx blocks.

Check your sources if you used "else if" instead elseif.
Else If opens a new, child IF block, and does not close the current IF block.

This one
if(A)
else(A)
  if(B)
  endif(B)
endif(A)

is the same as
if(A)
else(A) if(B)

endif(B)
endif(A) ' additional close is required


But when using ELSEIF:
if
elseif
endif

sapero

June 24, 2011, 04:54:17 AM #2 Last Edit: June 24, 2011, 11:06:04 AM by sapero
Done, the new checks are added, and waiting for Larry to compile.
They will check for while, do, if, type, interface, class, for, select, try, catch, with, else.

Robert34

Thanks very much, Sapero.
In version 1.73 of EBasic, the mismatched if-endif pairs appear to not be flagged until the end of the program. Several times I've had to do a binary search by patching in an extra endif to find the routine where the problem is.
It looks like it's time for me to upgrade :)

-- Robert

billhsln

June 24, 2011, 01:06:41 PM #4 Last Edit: June 24, 2011, 01:08:28 PM by billhsln
Old programmers (like me) usually just indent the code.  Makes it easier to follow and document.

dir = FINDOPEN(Npath)
IF (dir)
   DO
      Cpath = FINDNEXT(dir,attrib)
      IF Cpath <> ""
         IF (attrib & @file_directory)
            Opath = ""
         ELSE
            scntr++
            Opath = "Pic_" + USING("0###",scntr) + ".jpg"
            IF RENAME(Path + Cpath, Path + Opath)
               PRINT Cpath, " Renamed to ", Opath
            ELSE
               PRINT Cpath, " NOT Renamed to ", Opath
            ENDIF
         ENDIF
      ENDIF
   UNTIL Cpath = ""
   FINDCLOSE dir
ENDIF

Etc....

Bill
When all else fails, get a bigger hammer.

LarryMc

I'm with you, Bill, on the indenting.
I can't read/write code without indenting.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Hi,

As Larry knows, I hate the indenting! Seems like I set out my own style
of writing years ago, and anything else looks like a foreign language to me!

What you get used to, I guess

Brian

aurelCB

I dont care to much for indenting and i know for this error matching problem but i dont use this to serius.

ckoehn

I feel like Bill and Larry.  I've programmed for over 30 years (I started young :)),  it makes for much more readable code.  I've been working on someones code that was not "properly indented" and it is a complete headache to follow his program flow logic.

Clint

billhsln

The only thing worse than code without indenting is code with lots of GOTO's.  (Bad style).

Bill
When all else fails, get a bigger hammer.

mrainey

Quoteit makes for much more readable code

That's my opinion as well.
Software For Metalworking
http://closetolerancesoftware.com