Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
L ldpl
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 8
    • Issues 8
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Lartu
  • ldpl
  • Merge requests
  • !115

Merged
Created Jun 15, 2019 by Damián Garro@dgarroContributor

FOR statement

  • Overview 8
  • Commits 3
  • Changes 2

This adds a FOR statement, following this syntax:

FOR i FROM x TO y STEP z DO
    #FOR body
NEXT

where i is a number variable and x, y and z are number variables or literals.

First, it assigns x to i and starts an iteration. At the start of an iteration, the condition i <= y is evaluated if x < y and i >= y otherwise. If the condition passes, the FOR body is executed, if it fails the loop ends. After the body is executed, i is incremented by z and a new iteration is started (checking the condition and so on).

The BREAK and CONTINUE statements can be using inside FOR loops.

I used NEXT to mark the end of a FOR loop, but it could be REPEAT like in the WHILE loop without any trouble, if you prefer it.

Examples:

DATA:
i is number
PROCEDURE:
for i from 0 to 10 step 2 do
    if i is greater than 7 then
        break
    end if
    display i " "
next

outputs 0 2 4 6 .

DATA:
i is number
PROCEDURE:
for i from 5 to 0 step -1 do
    if i is equal to 3 then
        continue
    end if
    display i " "
next

outputs 5 4 2 1 0 .

Assignee
Assign to
Reviewer
Request review from
None
Milestone
None
Assign milestone
Time tracking
Source branch: github/fork/dgarroDC/for