cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Using "break" in a function to break a loop or other construct outside the function.

OI_8877786
3-Visitor

Using "break" in a function to break a loop or other construct outside the function.

Hello. I have a service, it must stop under a certain condition. This condition must contain the "break" construct. I need to make sure that this condition is called literally after every line in the script code. Of course, I did it, but in the end the code turned out to be huge. I tried to shorten it by putting the condition with "break" into the function, and taking the function out of the code. But as I understand it, "break" does not allow it to be used in this way. How it is possible to implement it correctly and beautifully?

1 REPLY 1

@OI_8877786

If the code you are writing to test the condition is complex, putting it is a function seems like a good choice.

From your description I assume that the "Break" just ends the function. Not your goal. Another approach would have the function return a Boolean which would be a simple test in in the main code to determine if you should continue.

I believe there is also an exit command which might accomplish your goal.

Announcements


Top Tags