FOR i ...

new topic     » topic index » view thread      » older message » newer message

It seems to me that the point of difference is whether or not the coder wants
the iterator variable to be declared in the FOR statement or prior to the FOR
statement. So may I suggest that we develop syntax that allows the coder to tell
Euphoria what their intention or expectation is. The current FOR syntax tells
Euphoria that the coder expects that the iterator variable is to be declared in
the FOR statement and scoped to the FOR statement.

    -- At this point 'i' is assumed not to exist yet,
    -- and in fact if it does, an error is raised.
    for i = A to B by C do
    -- 'i' is now declared and can be used inside the FOR block.
        ...
    end for
    -- 'i' is no longer visible or accessible.

We could develop a form of this syntax that allows the coder to tell Euphoria to
use a prior declaration for the iterator variable. Maybe something along the
lines of ...

    integer i
    -- At this point 'i' exists.
    for <res-word> i = A to B by C do
    -- The previously declared 'i' can be used inside the FOR block.
        ...
    end for
    -- 'i' is still visible and accessible.

where <res-word> is some existing reserved word, such as "with".

   integer i
   i = 20
   ? i
   for with i = 1 to 5 do
      ? i
   end for
   ? i

The output would be ...

20
1
2
3
4
5
6

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu