Skip to content

for loop #241

@jacobwilliams

Description

@jacobwilliams

Not sure if this has already been proposed or not. But I keep wishing Fortran had something like the python for style loops like this:

for x in [10, 23, 1]:
   do_something(x)

or with zip:

for x,y in zip([10,23,1], ['a', 'b', 'cc']):
  do_something(x,y)

of course, the fortran way would be something like that:

integer :: i  ! just a counter
integer,dimension(3),parameter :: vals = [10, 23, 1]
character(len=2),dimension(3),parameter :: cals = ['a ', 'b ', 'cc']
do i = 1, 3
  call do_something(vals(i), cals(i))
end do

What do people think?

I don't know what the syntax would be...

for (x => [10, 23, 1], c => ['a ', 'b ', 'cc'])
  call do_something(x,c)
end for

Metadata

Metadata

Assignees

No one assigned

    Labels

    Clause 11Standard Clause 11: Execution control

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions