Endif without if

Here we can discuss about the problem found
Post Reply
Stuart
Posts: 138
Joined: Fri Feb 19, 2021 7:46 pm
Has thanked: 5 times
Been thanked: 20 times

Endif without if

Post by Stuart »

I have been getting a few 'endif without if' errors on correct code. So far, recoding to get the commands on one line fixed them, I think. I won't post the code (~1000 lines) but something to bear in mind. That was with 1.48.22
User avatar
cicciocb
Site Admin
Posts: 2069
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 441 times
Been thanked: 1364 times
Contact:

Re: Endif without if

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Fri Oct 20, 2023 6:58 am I have been getting a few 'endif without if' errors on correct code. So far, recoding to get the commands on one line fixed them, I think. I won't post the code (~1000 lines) but something to bear in mind. That was with 1.48.22
Hi,
the "beautifier" works considering one instruction / command per line.
This is the best and clearer way to make and maintain a program.

So, as per your description, this cannot be considered a bug 8-)
Stuart
Posts: 138
Joined: Fri Feb 19, 2021 7:46 pm
Has thanked: 5 times
Been thanked: 20 times

Re: Endif without if

Post by Stuart »

Yes i understand that. Putting commands on the same line was an attempt to avoid else and endif statements. But it is not just a matter of colons. This is the most recent example:

This code generates an error ....
'==============
apply_controls:
intended_state$ = "on"
gosub adjust_flow_temperature
if proposed_state$ = "off" then intended_state$ = "off"
gosub adjust_return_temperature
if proposed_state$ = "off" then intended_state$ = "off"
gosub allow_for_weather
if proposed_state$ = "off" then intended_state$ = "off"
if intended_state$ = "on" then
boiler_message$ = "boiler may heat"
ensure_boiler_on [a sub]
else
'boiler_message already set
ensure_boiler_off [another sub]
endif --> generates 'ENDIF without IF' error
return

whereas this code which is functionally the same but is clumsier with split If statements, works without error
'==============
apply_controls:
intended_state$ = "on"
gosub adjust_flow_temperature
if proposed_state$ = "off" then intended_state$ = "off"
gosub adjust_return_temperature
if proposed_state$ = "off" then intended_state$ = "off"
gosub allow_for_weather
if proposed_state$ = "off" then intended_state$ = "off"
if intended_state$ = "on" then
boiler_message$ = "boiler may heat"
ensure_boiler_on
endif
if intended_state$ = "off" then
'boiler_message already set
ensure_boiler_off
endif
return
Stuart
Posts: 138
Joined: Fri Feb 19, 2021 7:46 pm
Has thanked: 5 times
Been thanked: 20 times

Re: Endif without if

Post by Stuart »

And now, after several hours running, that code has had the same error. I have several times been through the code checking for matching if/endif and not found any missing. I will do that again.
User avatar
PeterN
Posts: 393
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 184 times
Been thanked: 221 times
Contact:

Re: Endif without if

Post by PeterN »

This seems to be a question of ELSE standing alone or not.
The documentation requires it standing alone on the line

Try this :
wlog "--- ELSE INLINE"
for x= 1 to 5
if x and 1 then
wlog x, "odd"
else wlog x, "even"
endif
next x

wlog "--- ELSE OFFLINE"
for x= 1 to 5
if x and 1 then
wlog x, "odd"
else
wlog x, "even"
endif
next x


WLOG_OUTPUT:
--- ELSE INLINE
1 odd
3 odd
5 odd
--- ELSE OFFLINE
1 odd
2 even
3 odd
4 even
5 odd
User avatar
cicciocb
Site Admin
Posts: 2069
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 441 times
Been thanked: 1364 times
Contact:

Re: Endif without if

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sat Oct 21, 2023 4:57 pm And now, after several hours running, that code has had the same error. I have several times been through the code checking for matching if/endif and not found any missing. I will do that again.
Have you tried to use the beautifier button ?
It should help you to find the error
image.png
You do not have the required permissions to view the files attached to this post.
User avatar
PeterN
Posts: 393
Joined: Mon Feb 08, 2021 7:56 pm
Location: Krefeld, Germany
Has thanked: 184 times
Been thanked: 221 times
Contact:

Re: Endif without if

Post by PeterN »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Sat Oct 21, 2023 5:00 pm ...
This seems to be a question of ELSE standing alone or not.
The documentation requires it standing alone on the line
Oops !!! ... looking at your code again now, and I'm not on a mobile device anymore ... I can't see an ELSE with a following statement in the same line
The reason would have been too nice :-)
Is this called wishful thinking??
Stuart
Posts: 138
Joined: Fri Feb 19, 2021 7:46 pm
Has thanked: 5 times
Been thanked: 20 times

Re: Endif without if

Post by Stuart »

Still having issues. Could it be related to something other than IF statements?

I have 15 x:
if --- then --- [of which 4x have else ---]

32 x:
if --- then
---
endif

and 12 x
if --- then
---
else
---
endif

All check out as far as I can see. There are no labels in any if statements, and no nested if statements (I have done a lot of simplifying).
I have made it reboot on error so at least it continues to do its job.

I tried the green tick but it doesn't seem to do anything. My code is well laid out anyway. Should there be some output?
User avatar
cicciocb
Site Admin
Posts: 2069
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 441 times
Been thanked: 1364 times
Contact:

Re: Endif without if

Post by cicciocb »

If you want send me your code in private, I'll give an eye
Post Reply