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

How to do a return from a loop

Expand Messages
  • duke_nukem_time
    I ve looked and looked and I still can t figure the command to use when you want to return to the parent loop after going to a dependent loop. What i mean is
    Message 1 of 6 , Jun 17, 2007
      I've looked and looked and I still can't figure the command to use
      when you want to return to the parent loop after going to a dependent
      loop.
      What i mean is this.

      :Loop

      ;Call a dependent loop
      ^!Goto Loop2

      ^!Goto Loop

      :Loop2
      ;Return to the place where you called that loop
      ;?
    • abairheart
      Calling one loop from another is best dealt with by nested loops, example with two loop counters: ^!Set %O%=0; %maxO%=whatever; %maxI%=whatever ... ^!Inc %o%
      Message 2 of 6 , Jun 18, 2007
        Calling one loop from another is best dealt with
        by nested loops, example with two loop counters:


        ^!Set %O%=0; %maxO%=whatever; %maxI%=whatever
        :LOOP_OUTER
        ^!Inc %o%
        ;inside outer loop
        ;before inner loop
        ^!Set %i%=0
        :LOOP_INNER
        ^!Inc %i%
        ;inside both loops
        ^!If ^%i%<^%maxI% LOOP_INNER
        ;automatically drops out to outer loop,
        ;after inner loop
        ;inside outer loop
        ;when the test fails
        ^!If ^%o%<^%maxO% LOOP_OUTER


        Abair

        --- In ntb-clips@yahoogroups.com, "duke_nukem_time"
        <duke_nukem_time@...> wrote:
        >
        > I've looked and looked and I still can't figure the command to use
        > when you want to return to the parent loop after going to a dependent
        > loop.
        > What i mean is this.
        >
        > :Loop
        >
        > ;Call a dependent loop
        > ^!Goto Loop2
        >
        > ^!Goto Loop
        >
        > :Loop2
        > ;Return to the place where you called that loop
        > ;?
        >
      • abairheart
        If the nested loops in my previous post are for some reason not workable, the command to return to the previous loop at the next line ... ;Call a dependent
        Message 3 of 6 , Jun 18, 2007
          If the nested loops in my previous post are for some reason not
          workable, the command to return to the previous loop at the next line
          after the call would require ANOTHER_LABEL:


          :Loop

          ;Call a dependent loop
          ^!Goto Loop2
          :ANOTHER_LABEL

          ^!Goto Loop

          :Loop2
          ;Return to the place where you called that loop
          ^!Goto ANOTHER_LABEL



          Abair


          --- In ntb-clips@yahoogroups.com, "duke_nukem_time"
          <duke_nukem_time@...> wrote:
          >
          > I've looked and looked and I still can't figure the command to use
          > when you want to return to the parent loop after going to a dependent
          > loop.
          > What i mean is this.
          >
          > :Loop
          >
          > ;Call a dependent loop
          > ^!Goto Loop2
          >
          > ^!Goto Loop
          >
          > :Loop2
          > ;Return to the place where you called that loop
          > ;?
          >
        • duke_nukem_time
          See, I wasn t sure that they had Do-While or For loops in NoteTab as they do in C++. What I wanted to know was how to do a call return from a loop inside a
          Message 4 of 6 , Jun 18, 2007
            See, I wasn't sure that they had Do-While or For loops in NoteTab as
            they do in C++. What I wanted to know was how to do a call return from
            a loop inside a dependent clip back to the parent clip or call a loop
            from a dependent clip. For ex:

            Parent Clip

            :Loop A
            ;^!Goto LoopC?
            :Loop B
            ^!Goto Loop A

            Dependent Clip

            :Loop C
            ;^!Goto Loop B?

            A ^!Return command would be nice since it would allow me to use that
            to return from the loop I called instead of doing spaghetti code with
            the loops like I did above.
          • buralex@gmail.com
            ... 7:54:33 PM -0400 ... Have a look at commands ^!clip (executes another clip in same library) and ^!farclip (executes a clip another specified library). Both
            Message 5 of 6 , Jun 18, 2007
              > "duke_nukem_time" <duke_nukem_time@...> said on 06/18/2007
              7:54:33 PM -0400
              > A ^!Return command would be nice since it would allow me to use that
              > to return from the loop I called instead of doing spaghetti code with
              > the loops like I did above.
              Have a look at commands ^!clip (executes another clip in same library)
              and ^!farclip (executes a clip another specified library).

              Both execute line following in calling clip upon "return"

              Regards ... Alec -- buralex-gmail
              --
            • abairheart
              Anytime you exit a clip with the built-in END label from a clip, or you just reach the end of the clip, you return to where you called the clip from. The
              Message 6 of 6 , Jun 18, 2007
                Anytime you exit a clip with the built-in "END" label from a clip,
                or you just reach the end of the clip, you return to where you called
                the clip from. The example you cite is only a single clip.

                As subroutine, your stuf would look totally different:

                H="parent clip"
                :Loop
                ;blah blah
                ^!Clip "Subroutine clip"
                ;code after return from subroutine
                ^!Goto LOOP


                H="Subroutine clip"
                :LOOP
                ;code in subroutine loop
                ^!If condition LOOP
                ;when the clip reaches here, it automatically returns to caller


                SEE MORE BELOW

                --- In ntb-clips@yahoogroups.com, "duke_nukem_time"
                <duke_nukem_time@...> wrote:
                >
                > See, I wasn't sure that they had Do-While or For loops in NoteTab as
                > they do in C++.

                There is no specific "WHILE" loop in NoteTab, but it is easy enough to
                construct.

                > What I wanted to know was how to do a call return from
                > a loop inside a dependent clip back to the parent clip
                > or call a loop from a dependent clip.


                You seem to have misunderstood what a while loop (or any other kind of
                loop) is. In C++ or ANY programming language.

                Loops either just END or continue looping forever, or crash.
                Loops do not have a RETURN statement. Subroutines do.


                Clips are like subroutines (somewhat). Loops with Goto, and labels,
                are just program blocks WITHIN a subroutine (or method, or procedure,
                or function).


                MORE BELOW


                >For ex:
                >
                > Parent Clip
                >
                > :Loop A
                > ;^!Goto LoopC?
                > :Loop B
                > ^!Goto Loop A
                >
                > Dependent Clip
                >
                > :Loop C
                > ;^!Goto Loop B?
                >
                > A ^!Return command would be nice since it would allow me to use that
                > to return from the loop I called instead of doing spaghetti code with
                > the loops like I did above.
                >


                Actually, NoteTab DOES have the equivalent of a RETURN statement.

                Read up on Custom functions. NoteTab's RETURN is called "Result",
                and works in one of two ways:

                ^!Set %result%=data your want the custom funcction to return
                ;you can modify the %result% variable AFTER you have set it.

                For example

                ^!Set %result%=TRUE
                ^!If ^%foobar%<>37 ^!Set %result%=FALSE


                The other way to return a value is:

                ^!Result data your want the custom funcction to return
                ;to modify this data after this command, you would have to have a
                program flow to another ^!Result statement.


                Whether this clears it up or not, you ought to spend some time looking
                through the extensive NoteTab help system. In particular,

                Help==>Help On Clip Programming


                All the stuff above is explained there. Clearly you havn't spent any
                time at all there, which is sort of expected before you ask questions
                in discussion groups.

                RTFM


                Abair
              Your message has been successfully submitted and would be delivered to recipients shortly.