Loading ...
Sorry, an error occurred while loading the content.

23966Re: [Clip] Simple loop question

Expand Messages
  • Ian NTnerd
    Aug 29, 2013
    • 0 Attachment
      If you look in the Quick List (F6) there is an already made loop there.
      Look under:
      *Miscellaneous **Elements* then *Loop Element*

      It give you this:
      ^!Set %Index%=0
      ^!Set %LoopCount%=^?{How many loops?}
      ^!IfCancel End
      :LoopStart
      ^!Inc %Index%
      ^!If ^%Index% > ^%LoopCount% EndLoop

      *** Do something ***

      ^!GoTo LoopStart
      :EndLoop


      I use the slightly modified one below all the time. When you want to use
      a loop again you only need to write the starting *main *part and the
      *writeline *part but more likely another clip altogether. The *loopa
      *clip is totally reusable

      H="main"
      ; define the data to be processed.
      ; tell the array what separator to split the text into pieces with.
      ^!SetListDelimiter ^p
      ; arraya will separate each line into a different cell.
      ^!setarray %arraya%=^$GetFileText("c:\data.txt")$

      ; define the sub clip
      ^!set %subclip%=writeline

      ; I really would use:
      ; ^!set %subclip%=^$GetLibraryName$:writeline


      ; Now all is set up
      ; run the loopa and define the subclip to use by including it as a
      parameter of loopa.
      ^!clip "loopa" ^%subclip%

      ; I really would use:
      ; ^!farclip "call:loopa" ^%subclip%


      H="loopa"
      ^!Set %Indexa%=0
      ^!Set %LoopCounta%=^%arraya0%
      ^!IfCancel End

      :LoopStarta
      ^!Inc %Indexa%
      ^!If ^%Indexa% > ^%LoopCounta% EndLoopa

      ; next line skips over blank links in input file
      ^!If "^%arrayA^%indexA%%"="" LoopStarta

      ; The ^& will substitute the ^%subclip% parameter
      ; This now pass each line to another clip, defined above by the variable
      *subclip *to further process.
      ; Now the loopa can be used again. The subclip may call loopb and
      another subclip to further split the line content.
      ^!clip "^&" ^%arraya^%indexa%%

      ; I really use this line in my loopa clip in a clipbook called *call*. I
      just varied this for inclusion in the same clipbook.
      ; ^!farclip "^&" ^%arraya^%indexa%%

      ^!GoTo LoopStarta
      :EndLoopa

      H="writeline"
      ; the only reason for putting this part in a separate clip is so that
      loopa is totally reusable.
      Line length: ^$StrSize("^&")$
      Line: ^&


      This is untested as in I simplified what I usually use so it can be used
      in one clipbook.
      Have fun.

      Ian

      On 30/08/2013 12:08 AM, Celtics2000 wrote:
      >
      > Thank you very much!! I was definitely trying to do it the wrong way.
      >
      > ^!SetDebug On
      > ^!Set %Sum%=1
      > ^!Set %Sum%=(Calc(%Sum%+^?{}$))$
      >
      > :Loop
      > ^!If ^%Sum% = 0 ^!Goto True
      > WRITE HELLO WORLD NUMBER ^%Sum%
      > ^!Set %Sum%=(Calc(%Sum%-1))$
      > ^!Goto Loop
      >
      > -------------------
      >
      > --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com>,
      > loro <tabbie@...> wrote:
      > >
      > > At 21:36 2013-08-27, you wrote:
      > > >How do I create a simple loop that can be repeated by a variable
      > number input?
      > > >
      > > >For example I want to create a clip that can write "Hello World" and
      > > >I want to input how many times I want it repeated?
      > >
      > > Like this?
      > >
      > > ^!Set %repeat%=^?{How many times?}
      > >
      > > ^!Set %cntr%=0
      > > :loop
      > > ^!Inc %cntr%
      > > ^!If ^%cntr% > ^%repeat% end
      > > ^!InsertText Hello world^P
      > > ^!Goto loop
      > >
      > >
      > > That is you need a label (I called it 'loop', but you can call it
      > > anything). At the end of the clip you need to tell it to go to this
      > > label so the loop starts over.
      > > You need a counter (the variable called 'cntr') to keep track of how
      > > many times the loop has run. You do that by increasing it with 1 for
      > each loop.
      > > You need a conditional to check if the loop has run as many times as
      > > you want and if it has kill the clip (the ^!If line).
      > >
      > > Lotta
      > >
      >
      >



      [Non-text portions of this message have been removed]
    • Show all 6 messages in this topic