Endif in Do-Loop is skipped

85 views
Skip to first unread message

Oilaf

unread,
Jan 23, 2021, 12:14:09 PM1/23/21
to Annex WiFi RDS
Hello, it is the first post I write. Basically I am enthusiastic about the whole concept of Annex Wifi RDS for the ESP32. Since I don't know my way around that well, I'm not sure whether the error I found is mine or whether it is in the basic interpreter. I have a select case in which an if then is programmed in a do-loop and an if-then query in it. If the top If-Then query is negative, the program continues on the endif in the Do-Loop and generates an error with the endif outside the DO-Loop. Am I doing something wrong or the interpreter?

It is only a part of the program:
 CASE 4 :
      if Untermenue_a=0 then     'if Untermenue_a=1 then....
       TFT.FILL TFT.COLOR(WHITE)
       TFT.TEXT.COLOR TFT.COLOR(RED)
       Zeile_D=5
       index=1
       do
         temp$=file.read$("/Check_SD1.txt",index) 
         if MID$(temp$, len(temp$)-1 ,1)=":"then
           TFT.TEXT.DRAW temp$,10,Zeile_D
           Zeile_D=Zeile_D+15   
         endif     '....the program continues her
         index=index+1
       loop until left$(temp$,5)="_EOF_"     
      end if    '....then there is an ENDIF without IF line error here
     Untermenue=0
     Untermenue_a=1
   case 5 :


It's not my English, it's google translate

Oilaf

unread,
Jan 26, 2021, 3:23:40 PM1/26/21
to Annex WiFi RDS
Can't nobody understand the problem, or did I do something wrong in the post

Electroguard

unread,
Jan 26, 2021, 5:09:43 PM1/26/21
to Annex WiFi RDS
Hi Oilaf,

It would help others to help you if you gave a bit of an explanation of what you were trying to achieve with your code, because maybe someone might offer an alternative suggestion to avoid your problem but achieve your goal.

If you don't post your code, nobody can even try it - you may think the problem must be in the small sample you've given, but something like a missing END IF from a previous IF statement may not actually show up until the branch logic is tangled by a later IF ENDIF.

It is important to know what Annex version you are using, because bug fixes and changes cause different versions of Annex to behave differently in some circumstances.
In earlier versions for instance, following IF THEN branching logic with a 'comment could cause an error, which was  fixed in later versions.
 
Try to avoid anything unnecessary or ambiguous which might cause branching or logic errors.
For instance, Annex interprets the colon (:) to denote a BranchName, and/or to allow instructions to follow other instructions on the same line.
Therefore keeping the : at the end of CASE statements which do not have any following instruction might cause the interpreter to suffer branching or logic confusion.

Jumping out of loops/counts can cause problems if things haven't been tidied up beforehand.
That also applies to tests, eg: loop until (condition) will cause an error if the test of condition produces an error.

So it might help to pinpoint the problem by using a variable to separate the test condition from the test logic, eg…
...
goodbye = 0
do
...
if left$(temp$,5)="_EOF_" then goodbye = 1
loop until goodbye = 1


You would then be able to see if the error is actually generated by the IF THEN branching logic, or perhaps is instead caused by something wrong in the condition test.

Lizby

unread,
Jan 26, 2021, 5:27:33 PM1/26/21
to Annex WiFi RDS
"END" is a valid statement, and "IF" is a valid statement. Make sure that you have no space in "ENDIF"

cicciocb

unread,
Jan 27, 2021, 12:39:46 PM1/27/21
to Annex WiFi RDS

Hi Olav,
the problem comes from this line :
if MID$(temp$, len(temp$)-1 ,1)=":"then 
as there is no space between the ":" and then

For Lizby, ENDIF or END IF are both valid

Oilaf

unread,
Jan 29, 2021, 3:15:28 AM1/29/21
to Annex WiFi RDS
Many thanks for the help. Yes, of course it is correct to always show the whole code, but then everyone here in the forum would immediately see that I am a bad "spaghetti programmer" ;-) It should first be a test program for the hardware. I like to program a lot, but I'm not particularly good at it. The interpreter version is Annex32 WiFi 1.41 beta 5, next time I will state it right away.

@cicciocb, the space fixed the problem, thank you very much.

Fernando Perez

unread,
Jan 29, 2021, 5:35:25 AM1/29/21
to Annex WiFi RDS
File "/Check_SD1.txt"

I am line :1
I am line
2
I am line
:3
I am line
4
I am line
:5
I am line
6
I am line
:7
I am line
8
I am line
:9
I am line
10
_EOF_

wlog "First Loop"
index=1
do
  temp$=file.read$("/Check_SD1.txt",index)
  if MID$(temp$,len(temp$)-1,1)=":"then
    wlog temp$   
  endif     '....the program continues her
  index=index+1
loop until left$(temp$,5)="_EOF_"
wlog

wlog "Second Loop"
index=1
do
  temp$=file.read$("/Check_SD1.txt",index) 
  if MID$(temp$,len(temp$)-1,1)<>":"then
    wlog temp$   
  endif     '....the program continues her
  index=index+1
loop until left$(temp$,5)="_EOF_"
wlog

wlog "Third loop"

index = 1

do
  temp$ = file.read$("/Check_SD1.txt", index)

  if MID$(temp$, len(temp$) -1, 1) = ":" then
    wlog temp$   
  endif     '....the program continues her

  index = index + 1
loop until left$(temp$, 5) = "_EOF_"

wlog


wlog "Fourth loop"

index = 1

do
  temp$ = file.read$("/Check_SD1.txt", index) 
  if MID$(temp$, len(temp$)-1, 1) <> ":" then
    wlog temp$   
  endif     '....the program continues her
  index = index + 1
loop until left$(temp$, 5)="_EOF_"



cicciocb, I have uploaded these two files to an ESP32 and the result is the same, both with white space and without it:


First Loop
I am line
:1
I am line
:3
I am line
:5
I am line
:7
I am line
:9


Second Loop
I am line
2
I am line
4
I am line
6
I am line
8
I am line
10
_EOF_


Third loop
I am line
:1
I am line
:3
I am line
:5
I am line
:7
I am line
:9


Fourth loop
I am line
2
I am line
4
I am line
6
I am line
8
I am line
10
_EOF_

ciccio cb

unread,
Jan 29, 2021, 7:10:34 AM1/29/21
to Annex WiFi RDS
Hi Fernando,
the issue is related to the nested IF THEN.

In your example the problem cannot happen as there is just a DO with a single IF THEN inside.

In the Olaf's example, there is an IF with a DO and another IF inside.

--
You received this message because you are subscribed to the Google Groups "Annex WiFi RDS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to annex_wifi_rd...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/annex_wifi_rds/e691a9ab-e5dc-4d3c-9b0f-82b4b9c9de72o%40googlegroups.com.

Fernando Perez

unread,
Jan 30, 2021, 1:51:36 PM1/30/21
to Annex WiFi RDS
Hi Fernando,
the issue is related to the nested IF THEN.

In your example the problem cannot happen as there is just a DO with a single IF THEN inside.

In the Olaf's example, there is an IF with a DO and another IF inside.

---------------------------------------------------------------------------------------------------------------------------------------------
I'm sorry for wasting time, cicciocb, but when I don't understand something, I get stuck.
If I don't translate wrong, Oilaf's code fails because he forgot to put a blank space between the ":" and the then and because his structure is this:

if condition1 then
   
do
     
if condition2 then
       
.......
     endif
   loop
until condition3
endif



But I try my corrected code and I get that it works with and without white space, and that even the then is not necessary.
I do not get it.

wlog time$

while 1
  t
=millis : index=1

 
if index=1

   
do
      temp$
=file.read$("/Check_SD1.txt",index)
     
if MID$(temp$,len(temp$)-1,1)=":"

        wlog temp$  
      endif
      index
=index+1
    loop
until left$(temp$,5)="_EOF_"
  endif

  wlog
"Finish first loop in "; millis-t
  wlog
 
  t
=millis : index=1

 
if index=1then

   
do
      temp$
=file.read$("/Check_SD1.txt",index)
     
if MID$(temp$,len(temp$)-1,1)<>":"then

        wlog temp$  
      endif
      index
=index+1
    loop
until left$(temp$,5)="_EOF_"
  endif

  wlog
"Finish second loop in "; millis-t
  wlog  
 
wend


 

ciccio cb

unread,
Jan 30, 2021, 2:09:22 PM1/30/21
to Annex WiFi RDS
try to put index=0, you should be able to reproduce the problem

--
You received this message because you are subscribed to the Google Groups "Annex WiFi RDS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to annex_wifi_rd...@googlegroups.com.

Fernando Perez

unread,
Jan 30, 2021, 4:21:19 PM1/30/21
to Annex WiFi RDS
El sábado, 30 de enero de 2021, 20:09:22 (UTC+1), cicciocb escribió:
try to put index=0, you should be able to reproduce the problem


 Done. With index = 0, the problem appears. And, as always, you are right.
It is still curious that Annex works with or without "then".
Conclusion: If our ancestors already knew that "GOTO" cannot be used, we must avoid the devil and the nested loops.
As always, thank you Francesco.

ciccio cb

unread,
Jan 31, 2021, 4:28:23 AM1/31/21
to Annex WiFi RDS
Hi Fernando,
the THEN keyword is optional as stated in the documentation :

The IF can be nested

Example:

 

IF a=THEN

  IF b = 2 THEN

    IF c = 3 THEN

      PRINT "ok"

    END IF

  END IF

END IF

 

The “THEN” keyword can eventually be removed, even if this is not recommended.

Example:

 

IF > 100 print "a" else print "b"



There are no problems with nesting loops and IF, just always remember to put a space between the keywords as this may cause problems.


--
You received this message because you are subscribed to the Google Groups "Annex WiFi RDS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to annex_wifi_rd...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages