Is there a similar instruction to Break in C prog
ravi
✭
Hi,
I would like to know if there is an equivalent statement to that of Break statement in c language?
For example consider the for loop in a c program
for(i=0;i<10;i++)
{
if(i==5)
break;
}
when i is equal to 5 the for loop exits.How can I do the same in a RAPID program?
I would like to know if there is an equivalent statement to that of Break statement in c language?
For example consider the for loop in a c program
for(i=0;i<10;i++)
{
if(i==5)
break;
}
when i is equal to 5 the for loop exits.How can I do the same in a RAPID program?
0
Comments
-
RETURN;Russell Drown0
-
Hi,
I am using it in Main routine.As soon as return is executed the program pointer goes to the first instruction of the main.What I want is when return is executed it has to exit the for loop.
For example consider the below mentioned program
1 MODULE TestProgram
2 !This program for testing purpose
3 var num i1;
4 var num j1;
5 var num ww{3,4};
6 PROC main()
7 TPErase;
8 FOR j1 FROM 1 TO 5 DO
9 if j1=3 THEN
10 TPWrite"first for loop"NUM:=j1;
11 RETURN;
12 endif
13 if j1=4 THEN
14 TPWrite"second for loop"NUM:=j1;
15 ENDIF
16 ENDFOR
17 TPWrite""Num:=j1;
18 ENDPROC
19 ENDMODULE
If i use a return statement in line number 11,the program goes to the first instruction.But my requirement is that i has to exit the for loop when the instruction at line number 11 is executed.After that instruction at line number 17 has to be executed.Is there a way to do this??
Ravi
0 -
Break your program up into procedure or function calls that return you back into main.
Russell Drown0 -
Try
1 MODULE TestProgram
2 !This program for testing purpose
3 var num i1;
4 var num j1;
5 var num ww{3,4};
PROC Loop()
FOR j1 FROM 1 TO 5 DO
if j1=3 THEN
TPWrite"first for loop"NUM:=j1;
RETURN;
endif
if j1=4 THEN
TPWrite"second for loop"NUM:=j1;
ENDIF
ENDFOR
ENDRPOC
6 PROC main()
7 TPErase;
Loop;
17 TPWrite""Num:=j1;
18 ENDPROC
19 ENDMODULE
Main routine will call "loop" routine.
When j1 = 3 the "loop" will reutrn PP to Main, line "17".
J1 will never reach 4 thus never display "second for loop"
/eiven
Eiven
Win 7-64
RS 5.15RC1
Q9950 16gb0 -
Hi
The j1 is declaired two times. Once inside the FOR ... ENDFOR and once outside with var num j1. So you will not see the the last value of j1 from inside the loop in line 17. It will only show the start value, witch is not declaired.
The solution with RETURN should work.An other solution:FOR j1 FROM 1 TO 5 DO
IF j1<=3 THEN
if j1=3 THEN
TPWrite"first for loop"NUM:=j1;
endifif j1=4 THEN
TPWrite"second for loop"NUM:=j1;
ENDIF
ENDIF
ENDFORAn other solution:IF j1=0;
WHILE j1<5 DOj1:=j1+1;
if j1=3 THEN
TPWrite"first for loop"NUM:=j1;j1:=5;
endifif j1=4 THEN
TPWrite"second for loop"NUM:=j1;
ENDIF
ENDWHILEBest regardsMarcel
0 -
Greetings all,
I think that the critical part to getting this to work past line 11 is the fact that the value of j1 is only present within the FOR NEXT loop. Each time you reenter the loop, the value of j1 is reinitialized. You should then maybe look at storing the j1 value in another persistant variable before exiting and then upon reentry, initialize j1 as the value of the persistant variable. Good luck,Lee Justice0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 800 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings