[Scilab-users] Start an arrested loop with one keystroke only

Jens j.s.strom at hslmg.de
Tue Nov 22 20:22:32 CET 2016


Hallo Rafael,
Your solution is impressingly concise and works for 'while' and 'for'. 
My function preference is caused by the idea to use it in absence of 
loops too and that I understand it  still after a while. I have amended 
it in that respect:

function  k=stopgoclick(k,n)//mouseclick control of consecutive figures inside a while loop or in absence of a loop
         //INPUT
         //k: figure loop counter, or 1  if there is no loop
         //n: length of figure loop, or %i if there is no loop
         //left mouse click: continue loop i. e. next figure  (b(1)=3)
         //middle mouse click: abort script  (b(1)=4)
         //right mouse click: break loop (b(1)=5), for the non loop case right and left mouseclick are equivalent
         //OUTPUT
         //k=n for loop case after a right mouse click to break loop,  else: k from input
         //k for non loop case: the function is called without the output argument k.
         //Example for loop case: i=1; while i<=n; plot(x,i*x); i=stopgoclick(i,n);  i=i+1; end
         //Example for non loop case: stopgoclick(1,%i)
         b=xclick()
         if  b(1)==3//left mouse: next image
            return  
        elseif  b(1)==4//middle mouse: end script
            disp('script aborted')
            abort
        elseif  b(1)==5//break loop, or next image for non loop case
           if  isreal(n)
              k=n+1
              disp('figures finished')
           else
             return
           end
        end       
endfunction


The disadvantage is that the function does not allow 'for' loops.

Cheers
Jens
-------------------------------------------------------------------------------------

Am 22.11.2016 17:45, schrieb Rafael Guerra [via Scilab / Xcos - Mailing 
Lists Archives]:
>
> Hi Jens,
>
> I like the idea of using a function but could not find out right way 
> how to simplify and generalize yours for arbitrary loops.
>
> If instead of using a function, we copy the following line into "any" 
> for or while loop we will get the same result as in your particular 
> example:
>
> /// START OF CODE/
>
> _clf_;
>
> x=0:1;
>
> fori=1:10
>
> _plot_(x,i*x)
>
> b=xclick(); if b(1)==4 then abort elseif b(1)==5 then break end///copy 
> this inside any while/for loops/
>
> end
>
> /// END OF CODE/
>
> Regards,
>
> Rafael
>
> *From:*users [mailto:[hidden email] 
> </user/SendEmail.jtp?type=node&node=4035061&i=0>] *On Behalf Of *Jens
> *Sent:* Tuesday, November 22, 2016 4:27 PM
> *To:* [hidden email] </user/SendEmail.jtp?type=node&node=4035061&i=1>
> *Subject:* Re: [Scilab-users] Start an arrested loop with one 
> keystroke only
>
> Hallo Tim,
> I have answered my  last question by 'while' instead of 'for':
>
> function  *k*=_stopgoclick_(*k*,*n*)///control a figure loop bymouseclicks/
>          ///INPUT/
>          ///k: figure loop counter/
>          ///n: length of figure loop/
>          ///left mouse click: continue loopi. e. next figure   (b(1)=3)/
>          ///middle mouse click: abort script   (b(1)=4)/
>          ///right mouse click: break loop (b(1)=5)/
>          ///OUTPUT/
>          ///k; n after right mouse click to break loop,   else: k from input/
>          ///Example:i=1; whilei<=n; plot(x,i*x);i=stopgoclick(i,n);   i=i+1; end/
>          b=xclick()
>          if  b(1)==3///left mouse: next image/
>             return  
>         elseif  b(1)==4///middle mouse: end script/
>             abort
>         elseif  b(1)==5///break loop/
>             *k*=*n*+1
>          end  
> endfunction
>   
>      x=0:1;
>      n=10;
>      i=1;
> while  i<=n
>      _plot_(x,i*x)
>      i=_stopgoclick_(i,n);     
>      i=i+1;
> end
> 'further commands'
>   
>   
>
> I am satisfied with the function. Please advise if a simpler solution 
> exists.
> Cheers
> Jens
>
>
> _______________________________________________
> users mailing list
> [hidden email] </user/SendEmail.jtp?type=node&node=4035061&i=2>
> http://lists.scilab.org/mailman/listinfo/users
>
>
> ------------------------------------------------------------------------
> If you reply to this email, your message will be added to the 
> discussion below:
> http://mailinglists.scilab.org/Start-an-arrested-loop-with-one-keystroke-only-tp4035053p4035061.html 
>
> To unsubscribe from Start an arrested loop with one keystroke only, 
> click here 
> <http://mailinglists.scilab.org/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4035053&code=ai5zLnN0cm9tQGhzbG1nLmRlfDQwMzUwNTN8LTIyMzcxNjc3Ng==>.
> NAML 
> <http://mailinglists.scilab.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> 
>





--
View this message in context: http://mailinglists.scilab.org/Start-an-arrested-loop-with-one-keystroke-only-tp4035053p4035062.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20161122/01dbbb74/attachment.htm>


More information about the users mailing list