BBC BASIC
Programming >> BBC BASIC Language >> OPENIN"" and FOR-NEXT clarifications
http://bbcbasic.conforums.com/index.cgi?board=language&action=display&num=1517662234

OPENIN"" and FOR-NEXT clarifications
Post by pez on Feb 3rd, 2018, 11:50am

Dear Mr. Russell,

Would you, please, clarify for me the following confusing me matters?

OPENIN""
In which way I could catch the entered filename?

FOR-NEXT
0 may I suppose that I could use multiple NEXT lines for only one FOR line?

1 the comparison occurs at the FOR line or at the 1st NEXT line, which will be met after the FOR line?

2 the increment-decrement occurs at the FOR line or at the 1st NEXT line that will be met?

3 is the the loop body always executed at least once or that depends on the comparison?

4 the kind of comparison depends on the start-end values or it is always the same?

5 in any case, which of the following kinds of comparison are considered: (a) equal-unequal, (b) lower-greater, or (c) lower or equal - equal or greater?

6 the increment-decrement happens before or after the comparison?

Thanking you in advance,

Sincerely yours,

Petros Zimourtopoulos
Re: OPENIN"" and FOR-NEXT clarifications
Post by Richard Russell on Feb 3rd, 2018, 1:15pm

on Feb 3rd, 2018, 11:50am, pez wrote:
OPENIN""
In which way I could catch the entered filename?

I don't recommend that you use that feature because it's not supported in BBCSDL (SDL doesn't provide a file selector that OPENIN could call). Writing BB4W-specific code is naturally not something that I want to encourage, particularly at this forum!

However, with the above proviso, the answer to your query can be found at the Wiki.

Quote:
may I suppose that I could use multiple NEXT lines for only one FOR line?

The interpreter will not stop you doing so (it won't even know that you have) but it's undesirable - not least because it will break the auto-indenting in the editor. Any situation in which you might be tempted to do that can surely be re-jigged to avoid it, with an attendant improvement in program structure.

Quote:
the comparison occurs at the FOR line or at the 1st NEXT line, which will be met after the FOR line? 2 the increment-decrement occurs at the FOR line or at the 1st NEXT line that will be met?

The FOR statement is executed only once; the NEXT statement is executed once per loop. So, apart from initialisation, everything happens in the NEXT.

Quote:
3 is the the loop body always executed at least once or that depends on the comparison?

In BBC BASIC, yes. Some BASIC dialects work differently however (for example Liberty BASIC) so you should be careful.

Quote:
which of the following kinds of comparison are considered: (a) equal-unequal, (b) lower-greater, or (c) lower or equal - equal or greater?

Definitely not equality; a loop using a floating-point control variable might never stop, because of the slight errors inherent in many non-integer arithmetic operations. As far as the other possibilities are concerned I'm not sure. The only guaranteed behaviour is when the loop variable, and both the start and end values, are integers. Otherwise it will depend on floating-point calculations, and you might even find that a loop executes a different number of times in BB4W v5 and v6!

Richard.
Re: OPENIN"" and FOR-NEXT clarifications
Post by pez on Feb 3rd, 2018, 4:56pm

Dear Mr. Russell,

Thank you very much for your prompt reply.

I will try to follow your suggestions.

Sincerely yours,

Petros Zimourtopoulos