May 01, 2024, 02:30:25 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Suggestion on FOR/NEXT syntax

Started by paravantis, December 18, 2006, 01:25:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

paravantis

Paul,

The way things are now, we have to include the loop variable after NEXT, e.g.

FOR i=1 to 100
...
NEXT i


although at compile time it is obvious that a NEXT command terminates the last FOR loop.

Would you please consider dropping this requirement so that

FOR i=1 to 100
...
NEXT


becomes legal?

John

Kale

This may sound a little obtuse, but why would you want this? :)

GWS

Problem with that John, is in multiple loops .. the Next i , Next j , Next k .. help to identify the end of the loop.

Admittedly, the code indentation should do that, but all Basics I've met use the 'Next x' format.

best wishes, :)

Graham
Tomorrow may be too late ..

paravantis

In my programs I use multiple nested FOR/NEXT loops that span several screenfulls and it is a hustle to remember which loop variable corresponds to which NEXT.

In any case it is absolutely useless. If you try to terminate loops that are improperly nested you get a syntax error.

If a user wishes to properly tag the end of a loop, he or she may do so in a comment! Why impose it as a requirement?

John

paravantis

And, Graham, NOT all BASICs in widespread usage employ this mandatory loop index syntax: neither Powerbasic nor Purebasic require it.

John

GWS

Hm .. don't know about this one ..

Delphi has:

FOR i := 1 to 10 do begin
..
END;

Fortran has:

DO i = 1 , 10
..
END DO

but the good old Basic Forâ€Ã,¦ Next loop has been around since the earliest forms of the BASIC language ...
FOR iÂÃ, = 1 to 10
..
NEXT i

.. and Microsoft use it in that form .. so I'd have to vote for the historic format .. :)

Graham
Tomorrow may be too late ..

paravantis

Graham,

To enrich our discussion I would like to add that FREEBASIC also allows NEXTs without loop indexes and, if my memory does not fail me, Quickbasic also allowed what I propose.

John

J B Wood (Zumwalt)

I like really simple...

PLAY 100
GO


Hense, begins at 1, runs to100, and stops.
Don't ask me where I go that from, its a little scriptor I wrote years ago, had simplex combinations like this in it.
I even had:

REWIND 100
GO

Which simply started at 100 and worked its way backwards to 1, what good was that for?
Reverse indexing.
Silly, yea I know.

obelisk

I prefer the 'Next i" format. I just find it easier to follow the code.

GWS

Yep .. you're right about QuickBasic .. I'd more or less forgotten that one ..ÂÃ,  :)

Graham :)
Tomorrow may be too late ..

J B Wood (Zumwalt)

Bah ya got to be creative!

FOR Kids=1 to 10
...IF Kids > 1 THEN
......Parents="Go Crazy"
...END IF
NEXT kids

Kale

Quote from: paravantis on December 18, 2006, 01:38:00 PM
In my programs I use multiple nested FOR/NEXT loops that span several screenfulls and it is a hustle to remember which loop variable corresponds to which NEXT.

In any case it is absolutely useless. If you try to terminate loops that are improperly nested you get a syntax error.

If a user wishes to properly tag the end of a loop, he or she may do so in a comment! Why impose it as a requirement?

John

He i go again sounding obtuse ;) , but it shouldn't be a hustle to remember which ending goes with what loop, You should know! You can always scroll back up and take a look. ;D

Even though other BASICs let the user decide to include the iterating variable or not i've always choose to include it at all times. This makes your code easier to understand for you and others.

paravantis

Kale,

Methinks that your footnote (by a famous European, none the less)

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away"

renders my syntax superior from a ...philosophical point of view!

My proposed syntax is also more ...environmentally friendly as programmers will expend less energy in scrolling up and down code windows in search of matching FOR/NEXT loops!

;D
John

Barney

My vote goes for the old variable to stay with the NEXT. It was like that in the first BASIC. It is how it should be. ;)

Barney

Tom Cone Jr

To me it's easier to include the index variable than it is to define a comment.   I'll be content as long as the option to include the index variable in the Next statement is retained. 

mrainey

I vote to keep it in, at least as an option.
Software For Metalworking
http://closetolerancesoftware.com

Dennisc

Quoterenders my syntax superior from a ...philosophical point of view!

Ah John - there is a philosopher in all Greeks waiting to come out :) :)

Geritismata

Dennis Comninos
Failure is only the opportunity to begin again more intelligently
www.denniscomninos.com

Ionic Wind Support Team

paravantis,
You should really try Aurora out.  It will have 5D arrays in the next update and can do the same console mode programming as Emergence BASIC.  The immediate difference you will notice is that the syntax is context based, as opposed to keyword based like BASIC languages are.

In Aurora, much like in C, the terminating character of any construct is the right brace character.  And the FOR loop is much more powerful in constucting meaningful loop logic.   BASIC languages traditionally treat a FOR loop as an integer counter, where context based languages treat the FOR loop as a conditional expression, allowing using any condition to control the termination of the loop. 

for( float b=1.1; b < 99.5; b+=.1)
{
} //terminates the for loop

Paul.
Ionic Wind Support Team

Barney

Just an idea. Why not introducing Aurora style FOR loop into Emergence Basic? That would really make it standing above the rest.

FLOAT b
FOR b=1.1 TO b<99.5 STEP 0.1
  ..do something..
NEXT b

Barney

erosolmi

December 19, 2006, 04:05:20 AM #19 Last Edit: December 19, 2006, 04:46:59 AM by erosolmi
From a parsing / translating point of view NEXT followed by index is more easy to handle and to error check because you have a variable to conpare to.
While a simple NEXT will oblidge parser to keep track of the many nesting FOR/NEXT levels you can have each with its starting/ending/increment/decrement.

My vote for: NEXT [optional control variable]

Regards
Eros


ADD: I'm not an expert of EBasic (just bought it) but I noted I cannot use non INT variables type in FOR/NEXT. Is it correct?

Jerry Muelver

I'm with erosolmi on this. Let the two languages do things each in their own language-specific way.

Brice Manuel


paravantis

Erosolmi,

QuoteFrom a parsing / translating point of view NEXT followed by index is more easy to handle and to error check because you have a variable to conpare to.
While a simple NEXT will oblidge parser to keep track of the many nesting FOR/NEXT levels you can have each with its starting/ending/increment/decrement.

NO.

You cannot nest loops the wrong way, e.g.

FOR i=1 to 10
   FOR j=1 to 100
NEXT i
   NEXT j

When eBasic encounters a NEXT is automatically terminates the LAST loop. There is absolutely no ambivalence, thus (in my view) the inclusion of the loop variable is redundant.

erosolmi

December 19, 2006, 08:03:06 AM #23 Last Edit: December 19, 2006, 08:23:39 AM by erosolmi
Paravantis, yes, I know that. And this error checking is possible because there is the controlling variable just after NEXT keyword.

I was talking about EBasic parser (pre-compilation phase I mean) and why (in my opinion) it was choosen to use NEXT + variable instead of a simple NEXT that terminates the most recent FOR.
To use a simple NEXT without any variable the parser have to store for each FOR which is the controlling variable, which are the starting, ending, increment/decrement values.
Instead to use a NEXT with a controlling variable you just need to check values.

Again, this is jus my opinion without knowing the inner parser secrets (I have no EBasic sources) so I can be 100% wrong.
At the end, eBasic is a parser + ASM code generator so the reasons why something is done in a certain way must be searched in the parser.
In my opinion current syntax is reduntant too but we have to understand the reasons why it was done in that way.

Regards
Eros

Rod

Just a quick comment on John's claim that the "i" in "next i" is absolutely useless.....

Depends on point of view. I have to agree that it is useless to the compiler. I believe, however, that it is useful to the programmer, to quickly and easily observe which loop is being terminated.

This appears to be a case of syntax forcing the programmer to do something that is good for the programmer, not for the compiler.

Besides, some day I might be the second poor schmuck to have to pick up and maintain a program!!!!!