Skip to content

For loop syntax enhancements #2783

Closed
Closed

Description

@pekkaklarck

Two highly related enhancement ideas to for loops:

  1. Don't require a colon as a marker like :FOR but instead require both FOR and IN to be all upper case.

  2. Support the pipe character as a block marker instead of a backslash.

Together these enhancements would allow writing current

*** Keywords ***
Example
    :FOR    ${x}    IN    @{STUFF}
    \    Keyword    ${x}
    \    Another keyword

like

*** Keywords ***
Example
    FOR    ${x}    IN    @{STUFF}
    |    Keyword    ${x}
    |    Another keyword

This is especially nice if we later add support for other programmatic structures like IF/ELSE. Compare

*** Keywords ***
Example
    :FOR    ${x}    IN    @{STUFF}
    \    Keyword    ${x}
    \    :IF    ${x} > 42
    \    \    Another keyword
    \    \    Yet another keyword
    \    :ELSE
    \    \    Keyword here too
    \    One keyword more    ${x}

with

*** Keywords ***
Example
    FOR    ${x}    IN    @{STUFF}
    |    Keyword    ${x}
    |    IF    ${x} > 42
    |    |    Another keyword
    |    |    Yet another keyword
    |    ELSE
    |    |    Keyword here too
    |    One keyword more    ${x}

UPDATE: This issue was just ideas and brainstorming. These concrete issues were submitted based on the discussion here:

Activity

  1. added this to the milestone on Feb 26, 2018
  2. adam-wypych commented on Mar 28, 2018

    @adam-wypych

    Is it will be only supported in TSV and TXT/ROBOT with no | pipe separated format?

  3. pekkaklarck commented on Mar 28, 2018

    @pekkaklarck
    MemberAuthor

    You don't get this same problem when using the pipe separate format as you can just use

    | FOR | ${x}            | IN   | @{STUFF} |
    |     | Keyword         | ${x} |          |
    |     | Another keyword |      |          |
    

    and don't need such escaping at all.


    UPDATE: Explicit END marker will be required also in this case. See #3009 for details.

  4. pekkaklarck commented on Mar 28, 2018

    @pekkaklarck
    MemberAuthor

    Notice that at the moment this issue is just in idea, not a concrete proposal. Removal of : from :FOR sounds like a good idea, but how to handle blocks when using the normal plain text format (i.e. not the pipe separated format) is still totally open.

    One possibility would be using significant whitespace like in Python:

    *** Keywords ***
    Example
        FOR    ${x}    IN    @{STUFF}
            Keyword    ${x}
            IF    ${x} > 42
                Another keyword
                Yet another keyword
            ELSE
                Keyword here too
            One keyword more    ${x}
    

    but that's likely to cause backwards incompatibility problems.

    Another solution would be closing blocks with END like in Ruby:

    *** Keywords ***
    Example
        FOR    ${x}    IN    @{STUFF}
            Keyword    ${x}
            IF    ${x} > 42
                Another keyword
                Yet another keyword
            ELSE
                Keyword here too
            END
            One keyword more    ${x}
        END
    
  5. adam-wypych commented on Mar 28, 2018

    @adam-wypych

    Thanks @pekkaklarck for clarification, so this syntax is only for not pipe separated format.

  6. basic-settings commented on Jul 5, 2018

    @basic-settings

    I'm really liking the END idea more than pipe separation.

  7. pekkaklarck commented on Oct 16, 2018

    @pekkaklarck
    MemberAuthor

    #2990 covers using just FOR (case-sensitive) as a marker and #2991 deprecates using IN, IN RANGE, and friends case- and space-insensitively. Both of them are targeted for RF 3.1.

    How to handle blocks is still open, but the pipe idea doesn't sound too good anymore. A separate and more concrete issue will be submitted about that later.

  8. removed this from the v3.1 milestone on Oct 16, 2018
  9. pekkaklarck commented on Nov 21, 2018

    @pekkaklarck
    MemberAuthor

    We decided to go with the END at the end. See #3009 for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions