IonicWind Software

IWBasic => IWB3.x Bug Reports => IW2.0 Bug Reports => Topic started by: Robert34 on June 23, 2011, 05:08:02 PM

Title: unmatched "IF" or "WHILE"
Post by: Robert34 on June 23, 2011, 05:08:02 PM
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
Title: Re: unmatched "IF" or "WHILE"
Post by: sapero on June 24, 2011, 01:09:27 AM
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
Title: Re: unmatched "IF" or "WHILE"
Post by: sapero on June 24, 2011, 04:54:17 AM
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.
Title: Re: unmatched "IF" or "WHILE"
Post by: Robert34 on June 24, 2011, 12:25:25 PM
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
Title: Re: unmatched "IF" or "WHILE"
Post by: billhsln on June 24, 2011, 01:06:41 PM
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
Title: Re: unmatched "IF" or "WHILE"
Post by: LarryMc on June 24, 2011, 02:48:52 PM
I'm with you, Bill, on the indenting.
I can't read/write code without indenting.

LarryMc
Title: Re: unmatched "IF" or "WHILE"
Post by: Brian on June 25, 2011, 03:19:53 AM
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
Title: Re: unmatched "IF" or "WHILE"
Post by: aurelCB on June 25, 2011, 04:10:33 AM
I dont care to much for indenting and i know for this error matching problem but i dont use this to serius.
Title: Re: unmatched "IF" or "WHILE"
Post by: ckoehn on June 25, 2011, 06:25:39 AM
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
Title: Re: unmatched "IF" or "WHILE"
Post by: billhsln on June 25, 2011, 08:01:04 AM
The only thing worse than code without indenting is code with lots of GOTO's.  (Bad style).

Bill
Title: Re: unmatched "IF" or "WHILE"
Post by: mrainey on June 26, 2011, 02:14:49 PM
Quoteit makes for much more readable code

That's my opinion as well.