Results 1 to 7 of 7

Thread: Using an IF statement inside a While looping

  1. #1
    Registered
    Join Date
    Jan 2009
    Location
    USA
    Posts
    39
    Downloads
    0
    Uploads
    0

    Using an IF statement inside a While looping

    Gentlemen
    I was wondering if I can put a IF conditional branching statement inside a While looping statement. The reason I want to do this is to make sure my radius in my tornado macro does not be come a negitive value. I wanted to fire an alarm if the radius got to small.

    WHILE[#101LE#110]DO1
    *****
    *****
    *****
    *****
    IF[#18LE.025]GOTO50
    END1

    N50
    #3000=101(RADIUS TO SMALL)


  2. #2
    Registered
    Join Date
    Jun 2008
    Location
    United States
    Posts
    1509
    Downloads
    0
    Uploads
    0
    You sure can. I do this all the time. When I write loops there is usually a pick size and a depth of some sort specified by the operator. The pick and the depth are not always divisible so I have an IF statement to set it equal to the final depth if it exceeds with the stack of the pick. Then it will end the loop. If it permits then set it up so if the next pass is going to be a negative radius number have it set itself to the minimum radius you specify, using the THEN statement.

    A simple facing program from OD to ID
    #1=0(Z-START)
    #2=.354(FINAL DEPTH)
    #3=.03(PICK SIZE)
    #4=60(OD DIAMETER)
    #5=59(ID DIAMETER)
    G0G90G55X#4Z3.M4
    WHILE[#1LT#2]DO1
    #1=#1+#3
    IF[#1GE#2]THEN#1=#2
    G0Z-#1
    G1X#5
    G0U.025W.025
    X#4M9
    END1

    Stevo


  3. #3
    Registered
    Join Date
    Jan 2009
    Location
    USA
    Posts
    39
    Downloads
    0
    Uploads
    0
    Stevo
    Thanks for thr replie,but with your example you are not jumping out of the loop like I am and I could use a THEN statement if my control will let me. By the way it's a pro5 makino sorry about not tell you guys before. So I guess my question is can I jump out of the loop to fire an alarm?


  4. #4
    Registered beege's Avatar
    Join Date
    Feb 2008
    Location
    USA
    Posts
    547
    Downloads
    0
    Uploads
    0
    Quote Originally Posted by ggborgen View Post
    Gentlemen
    I was wondering if I can put a IF conditional branching statement inside a While looping statement. The reason I want to do this is to make sure my radius in my tornado macro does not be come a negitive value. I wanted to fire an alarm if the radius got to small.

    WHILE[#101LE#110]DO1
    *****
    *****
    *****
    *****
    IF[#18LE.025]GOTO50
    END1

    N50
    #3000=101(RADIUS TO SMALL)
    I would think a nested WHILE/DO loop would suit.
    Where:
    WHILE[#18LE.025]DO1
    would start the whole thing off? (I don't program many macros, but this might inspire a better answer).
    D


  • #5
    Registered
    Join Date
    Jun 2008
    Location
    United States
    Posts
    1509
    Downloads
    0
    Uploads
    0
    Beege,
    That's a good idea, it will depend on what he is actually trying to acheive.

    ggborgen,
    The only way you are going to know is to try it. Do a simple WHILE loop moving the machine in incremental but cut in with the GOTO statement before the WHILE is satisfied.

    #1=0
    WHILE[#1LT5]DO1
    G0G91X1.
    #1=#1+1
    IF[#1EQ3]GOTO100
    END1
    N100M30

    If your machine incrementally moves 5” then it never jumped out. If it moved 3” and the program ended then it jumped out of the loop with the IF statement.

    You don't need to actually move the machine. You could use a dwell or something if you wanted. Or just use variables to count +1 and compare values.

    Stevo


  • #6
    Registered beege's Avatar
    Join Date
    Feb 2008
    Location
    USA
    Posts
    547
    Downloads
    0
    Uploads
    0
    Quote Originally Posted by stevo1 View Post
    Beege,
    That's a good idea, it will depend on what he is actually trying to acheive.

    ggborgen,
    The only way you are going to know is to try it. Do a simple WHILE loop moving the machine in incremental but cut in with the GOTO statement before the WHILE is satisfied.

    #1=0
    WHILE[#1LT5]DO1
    G0G91X1.
    #1=#1+1
    IF[#1EQ3]GOTO100
    END1
    N100M30

    If your machine incrementally moves 5” then it never jumped out. If it moved 3” and the program ended then it jumped out of the loop with the IF statement.

    You don't need to actually move the machine. You could use a dwell or something if you wanted. Or just use variables to count +1 and compare values.

    Stevo
    Is the control going to look for the END1 after the IF jumps you out of the loop?
    Last edited by beege; 06-23-2009 at 01:13 PM. Reason: Reword query


  • #7
    Registered
    Join Date
    Jun 2008
    Location
    United States
    Posts
    1509
    Downloads
    0
    Uploads
    0
    Quote Originally Posted by beege View Post
    Is the control going to look for the END1 after the IF jumps you out of the loop?
    Beege,

    If the WHILE statement gets satisfied meaning it never jumps out of the loop with the IF statement then it just goes to the next block proceeding the END1 which is a M30. If the IF statement works and it jumps out of the loop it will go to N100 which is a M30.

    WHILE statements only run between the WHILE and the END until the WHILE block is satisfied. Anything outside of that does not matter. Once it has left the loop it will not go back to it or care about any of its conditions unless you specify to return to it with a GOTO. To answer your question no it is not going to look for the END1. Good question...you are making me think for the first time today.

    I have jumped out of loops before conditions were met and don't recall any problems but for 99% of the time I use THEN conditions when in a loop as wrote in post2.

    This works on any machines I have worked on. Mainly Fanucs. It's macro programming so I see no reason why it should not work in this control.

    IIRC with the Fanucs you can have up to 3 WHILE statements within 1.

    Stevo


  • Similar Threads

    1. Replies: 104
      Last Post: 02-24-2009, 09:18 AM
    2. LOOPING? with Camsoft??
      By nelZ in forum CamSoft Products
      Replies: 15
      Last Post: 10-15-2008, 04:56 PM
    3. Need Help!- Fanuc O-T looping cycle
      By Billet Sean in forum General Metalwork Discussion
      Replies: 5
      Last Post: 04-28-2008, 03:11 PM
    4. Program Looping
      By Bohemund in forum CamSoft Products
      Replies: 7
      Last Post: 05-26-2007, 12:08 PM
    5. Sub Looping
      By murphyspost in forum Daewoo/Doosan
      Replies: 8
      Last Post: 12-27-2006, 11:28 AM

    Posting Permissions



    About CNCzone.com

      We are the largest and most active discussion forum from DIY CNC Machines to the Cad/Cam software to run them. The site is 100% free to join and use, so join today!

    Follow us on

    Facebook Dribbble RSS Feed


    Search Engine Friendly URLs by vBSEO ©2011, Crawlability, Inc.