Author Topic: Repeating things  (Read 3015 times)

Test96

  • Newbie
  • *
  • Posts: 5
Repeating things
« on: November 21, 2011, 08:03:27 AM »
Hi,

How can I make my app repeat something such as put 10, 100 or 1000 items in a field?
A friend told me there should be some commands like FOR, REPEAT, WHILE, DO but I haven't found an example yet.

Perhaps someone has a quick example or a link to one.


Malkom

  • Administrator
  • Sr. Member
  • *****
  • Posts: 287
Re: Repeating things
« Reply #1 on: November 21, 2011, 12:43:28 PM »
Hi,

How can I make my app repeat something such as put 10, 100 or 1000 items in a field?
A friend told me there should be some commands like FOR, REPEAT, WHILE, DO but I haven't found an example yet.

Perhaps someone has a quick example or a link to one.

Hi

There are two approaches to repeating things - usually called looping.

The first is when it is known in advance how many times the loop should repeat - this is called a FOR loop
eg, you want to display 10 items in your field.

The second is when it is not known in advance when the loop should end - this is called a WHILE loop
eg, you are reading items from a file but do not know how long the file is.


(1) This is the text from our help file on FOR loops:-


The "For" loop executes a series of statements. The loop can be exited by using the "Exitfor" statement.

Whether the loop goes up or down is dependent upon the step variable. If the step variable is omitted then it is assumed to be plus 1.

Code: [Select]
For x=1 to 10 step 1

  put line x of field 1 into y

  If y=2 then

     ExitFor

  EndIf

EndFor

Note, it is currently not possible to use a procedure or a function parameter as one of the limit variables.



(2) This is from our help file on WHILE loops:-

The "While" loop executes a series of statements until the terms evaluate to false.

The loop can be exited at any time by using the "ExitWhile" statement.

Code: [Select]
Put 1 into x

While (x<10)

    ...

    Put line x of field 1 into y

    If y=2 then

       ExitWhile

    EndIf

    ...

    Increment x

EndWhile








I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

Test96

  • Newbie
  • *
  • Posts: 5
Re: Repeating things
« Reply #2 on: November 22, 2011, 10:14:14 AM »
The For loop works fine, exactly what I needed, thank you.