Results 1 to 8 of 8

Thread: LOOP Function...

  1. #1
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default LOOP Function...

    Hi ALL,

    I would like to learn "LOOP" with LISP.
    The following is a sample:

    Code:
    Do TASK_01.
    Test CONDITION_01.
    If CONDITION_01 is nil,
    repeat TASK_01 until CONDITION_01 is true.
    Then the routine stops.
    Your helps are much appreciated.

  2. #2
    I could stop if I wanted to
    Join Date
    2005-09
    Location
    Canada
    Posts
    214
    Login to Give a bone
    0

    Default Re: LOOP Function...

    Quote Originally Posted by BoKirra View Post
    Hi ALL,

    I would like to learn "LOOP" with LISP.
    The following is a sample:

    Code:
    Do TASK_01.
    Test CONDITION_01.
    If CONDITION_01 is nil,
    repeat TASK_01 until CONDITION_01 is true.
    Then the routine stops.
    Your helps are much appreciated.
    eg:
    Code:
    (defun task1 ()
    (setq condition_01 (entsel "\nSelect your entity: " ))
    )  
    
    (while (not condition_01)
    (task1)  
    )

  3. #3
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default Re: LOOP Function...

    Quote Originally Posted by andrea.andreetti View Post
    eg:
    Code:
    (defun task1 ()
    (setq condition_01 (entsel "\nSelect your entity: " ))
    )  
     
    (while (not condition_01)
    (task1)  
    )
    Thanks.
    Can it be simplified?
    something like
    Code:
    (setq condition_01 (entsel "\nSelect your entity: " ))
     
    (while (not condition_01)
    (condition_01) 
    )
    and why?
    Last edited by BoKirra; 2009-03-09 at 11:52 PM.

  4. #4
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default Re: LOOP Function...

    A sample as below:
    Code:
    1) Define a diameter
    (setq Hole_Diameter (getreal "Enter Diameter: "))
    2) Draw a circle
    (command "circle" Insert_point "d" Hole_Diameter)
    3) Repeat step 1 and 2 until Hole_Diameter = 50
    4) Draw a center mark to the circle only when its Hole_Diameter = 50
    (command "line" point01 point02 "") ;point01 & point02 were predefined.
    (command "line" point03 point04 "") ;point03 & point04 were predefined.
    5) Routine stops.
     
    Note:
    This routine would draw as many circles as user inputted.
    The routine would not stop until a 50mm diameter circle drawn & center mark added.
    And there would be only one single circle drawn with 50mm diameter &
    only it would have a center mark.
    How to write this routine?
    Thanks in advance.
    Last edited by BoKirra; 2009-03-10 at 09:47 PM.

  5. #5
    I could stop if I wanted to
    Join Date
    2007-08
    Posts
    202
    Login to Give a bone
    0

    Default Re: LOOP Function...

    Hi,

    Code:
    (while (/= 50.0 (setq Hole_Diameter (getreal "Enter Diameter: ")))
      (command "_.circle" Insert_point "_d" Hole_Diameter)
    )
    (command "_.circle" Insert_point 25.0)
    (command "_.line" point01 point02 "")
    (command "_.line" point03 point04 "")

  6. #6
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: LOOP Function...

    Quote Originally Posted by BoKirra View Post
    Can it be simplified?
    something like
    Code:
    (setq condition_01 (entsel "\nSelect your entity: " ))
     
    (while (not condition_01)
    (condition_01) 
    )
    and why?
    It can be even simpler, the test is both checking & performing the action:
    Code:
    (while (not (setq condition_01 (entsel "\nSelect your entity: "))))
    Yours wouldn't work since condition_01 is simply a variable holding a value, not a function performing some action. That's whyandrea had the (setq ...) warped inside a defun and then calling the defun in the while loop.

  7. #7
    AUGI Addict
    Join Date
    2006-04
    Location
    (getpoint "Anywhere on the Enter Key =>")
    Posts
    1,160
    Login to Give a bone
    0

    Default Re: LOOP Function...

    Quote Originally Posted by irneb View Post
    It can be even simpler, the test is both checking & performing the action:
    Code:
    (while (not (setq condition_01 (entsel "\nSelect your entity: "))))
    Yours wouldn't work since condition_01 is simply a variable holding a value, not a function performing some action. That's why andrea had the (setq ...) warped inside a defun and then calling the defun in the while loop.
    Thanks. It works perfectly...
    Many thanks to irneb, gile & andrea.andreetti

  8. #8
    I could stop if I wanted to
    Join Date
    2005-09
    Location
    Canada
    Posts
    214
    Login to Give a bone
    0

    Default Re: LOOP Function...

    it's a pleasure..

Similar Threads

  1. End of while loop...
    By marko_ribar in forum AutoLISP
    Replies: 11
    Last Post: 2010-10-20, 07:55 PM
  2. how do i loop this?
    By mgonzales.224492 in forum AutoLISP
    Replies: 2
    Last Post: 2009-07-31, 06:41 PM
  3. Change the F1 function key to perform some other function
    By Spanky in forum AutoCAD Customization
    Replies: 7
    Last Post: 2007-11-28, 04:14 PM
  4. Help with Sub Function and calling it from main Function
    By avinash00002002 in forum VBA/COM Interop
    Replies: 1
    Last Post: 2006-06-21, 02:20 PM
  5. Block Insert Array (Loop within a Loop)
    By wpeacock in forum VBA/COM Interop
    Replies: 2
    Last Post: 2005-06-14, 04:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •