← 输入框|github.com|刷新
Skip to content

Implement looping through a string #206

Closed

Description

@namannimmo10

Reference code:

def main0():
    s: str
    s = 'aabbcc'
    c: str
    for c in s:
        print(c)

main0()

ASR:

semantic error: Only function call `range(..)` supported as for loop iteration for now
 --> c.py:5:5 - 6:16
  |
5 |        for c in s:
  |        ^^^^^^^^^^^...
...
  |
6 |            print(c)
  | ...^^^^^^^^^^^^^^^^

Activity

  1. Smit-create commented on Mar 10, 2022

    @Smit-create
    Collaborator

    This could be generalised for all iterable objects like tuples, list, etc.

  2. Smit-create commented on Jan 20, 2023

    @Smit-create
    Collaborator

    This works now:

    % cat a.py
    def main0():
        s: str
        s = 'aabbcc'
        c: str
        for c in s:
            print(c)
    
    main0()
    lpython % lpython a.py
    a
    a
    b
    b
    c
    c
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions