Highlighted
Respected Contributor.
Respected Contributor.
453 views

How to 'break' from an AM script having if-else condition?

Hi Experts,

I have a script with few if-elseif conditions. I want to break from the script when it meets a certain condition and do nothing after that.

Is there any AM equivalent for a 'break' statement in Java?

Thanks.

0 Likes
2 Replies
Highlighted
Micro Focus Frequent Contributor
Micro Focus Frequent Contributor

Check out this documenation link :

https://docs.microfocus.com/AM/9.70/Content/ProgrammersReference/ch01s02.html?Highlight=else condition

You will see there is a SELECT CASE statement - does this help you at all ?

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Using SELECT CASE is definatelly the way to go if you are checking the same field for multiple values.

However to answer your specific question I believe what you are looking for is "Exit Function".  You could also use a GoTo and a Label.  

=====================

<stuff>

If <condition 1> Then Goto ThisIsTheEnd

<stuff you want to skip>

ThisIsTheEnd:

=====================

You might have to check the Syntax on that since I am just freehanding this.  GoTo has gotten a bad rap over the years, but it has appropriate uses.  Just do not have Goto's crossing back over each other.  As a rule of thumb "Always Goto Farther On" is pretty safe.  It is all about Readability and Maintainablity.  If using a Goto makes your code cleaner and easier to read then it can be a good thing to do.

Cheers,

Russ

Russell Parker, CITAM, CHAMP, CSAM
President - Golden Ratio, Inc.
Russ.Parker@GoldenRatioInc.com
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.