LB Booster
« I wrote a wrong code! »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:32am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: I wrote a wrong code!  (Read 686 times)
SarmedNafi
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 93
xx I wrote a wrong code!
« Thread started on: Aug 9th, 2015, 03:54am »

The following code which I wrote is wrong.

But it is accepted by LBB and run it in wrong way, so a wrong result was displayed.

Code:

'code------
A=4

if A=2 then else print "3"
  print "2"
else
if A=4 then 
  print "4"
end if
end if

wait
'code-----

 


I hope Richard will take care of it at next release.

With all thanks to Richard
Regards,
Sarmed
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: I wrote a wrong code!
« Reply #1 on: Aug 9th, 2015, 07:11am »

on Aug 9th, 2015, 03:54am, SarmedNafi wrote:
I hope Richard will take care of it at next release.

It's unlikely, I'm afraid - BBC BASIC also accepts the equivalent program without reporting any error!

Richard.
User IP Logged

sirguylittle
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 3
xx Re: I wrote a wrong code!
« Reply #2 on: Aug 10th, 2015, 7:05pm »

First things first, Hi all. I have been lurking on this forum for long enough, so thought I would introduce myself and chip in :)

on Aug 9th, 2015, 03:54am, SarmedNafi wrote:
I hope Richard will take care of it at next release.


It would be quite difficult I think for a compiler to catch errors like this where the error stretches over multiple statements and is more due to faulty logic rather than a syntax error.

I believe this is why it is suggested that when constructs such as IF... THEN... ELSE... are used, that you do not mix the use of single line statements with multiple line ones.
IE either use IF... THEN... ELSE... on one line or use
IF... THEN
...
ELSE
...
END IF

but do not mix them.
For one thing, it will make your program easier to read and debug later and I think the separate line form is to be preferred for this reason.

In your particular example, SELECT CASE might be a better choice instead of using nested IF... THEN... ELSE... constructs.

Code:
A=4

SELECT CASE A
    CASE 2
        PRINT "2"
    CASE 3
        PRINT "3"
    CASE 4
        PRINT "4"
    CASE else
        PRINT "something else"
    END SELECT
 
« Last Edit: Aug 11th, 2015, 05:17am by sirguylittle » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls