LB Booster
« for,next »

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



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: for,next  (Read 165 times)
Alincon
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 147
xx for,next
« Thread started on: Mar 24th, 2017, 5:22pm »

The code below prints only one line, even though n>1.
Is the line "for n = 1 to n" not valid in LBB?

r.m.

Code:
 open fileName$ for input as #pjtTntNam
        n=0 : redim pjtTntNam$(99)
        while not (eof(#pjtTntNam))
            n = n+1
            input #pjtTntNam, pjtTntNam$(n)
        wend
    close #pjtTntNam
    sort pjtTntNam$(),1,n
    open fileName$ for output as #pjtTntNam
        for n = 1 to n
            print pjtTntNam$(n)
        next
    close #pjtTntNam

 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: for,next
« Reply #1 on: Mar 24th, 2017, 6:18pm »

on Mar 24th, 2017, 5:22pm, Alincon wrote:
Is the line "for n = 1 to n" not valid in LBB?

I wouldn't say it's "not valid" but it's certainly ambiguous. Nothing in the LB or LBB documentation tells you whether the initial 'n = 1' assignment happens before or after the evaluation of the 'to' value. In LBB it happens before, so it's equivalent to writing:

Code:
    for n = 1 to 1 

There are other ways of provoking different FOR..NEXT behaviors by writing ambiguous code. For example this:

Code:
    for n = 1 to 0
    next
    print n 

which prints 1 in LBB but 2 in LB 4.

The moral is: if you don't want uncertain results, don't write ambiguous code!

Richard.
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