# Thread: Using an IF statement inside a While looping

1. ## 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

2. 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. 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. Originally Posted by ggborgen
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
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

• 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

• Originally Posted by stevo1
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?

• Originally Posted by beege
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