Skip to content

Refactor for-loop to only check for upper or lower bound if direction is known at compile time #399

Open
@riederm

Description

@riederm

A for statement no checks whether the counter x is between startand end. this is handy if you dont really know where you're counting up or down (we dont know if step is positive or negative).

FOR x := start TO end BY step DO
   ...
END_FOR

so we do a check like:
x >= start && x <= end || x >= end && x <= start to accomodate for both situations (start < end -> counting up or start > end -> counting down)

if we know that we count up (or down) at compile time (e.g. if no step is provided, or it is a literal), we can skip several of the checks. when counting up, we only need to check against the x <= end ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions