Daniel Super Contributor.
Super Contributor.
1433 views

How to create a loop in HPOO

I need to create a loop/while that given a variable (numberOfServers) it prints once the name of the servers.

For example, in pseudo code:

numberOfServers = 2
serverName = []
while count <= numberOfServers:
    serverName.append('stageServer' + count)
    count += 1

print (serverName)

Is it possible to do something like this with flows?

Thanks

0 Likes
5 Replies
David_Teh Respected Contributor.
Respected Contributor.

Re: How to create a loop in HPOO

Hi Daniel, 

Not sure if mine is the most efficient but

1) to get the number, use an Addition while storing the output as a variable. (this will give you your count)

2) use Set Flow Variable to create an empty variable.

3) try using a List Iterator (delimited using perhaps a ',') to go through your array and store the output together with the count via List Appender

4) after appending via List Appender, use Addition again to increase your count by 1

I'm not very sure if step 3 will work for you because my usage was to go through a whole folder but theoretically I believe its sound. 

 

David

scuda20 Super Contributor.
Super Contributor.

Re: How to create a loop in HPOO

There are multiple ways you can approach it. Look in Utility Opertions at lists and Looping and Math and Comparison

If you already have a list, you can use the the list iterator which will keep track of the number and perform the action on each item. If you are building a list but only want a certain size, then you would 1.) set an empty flow variable (example listCount) 2.) list appender 3.) peform action 4.) use Equal to check the listCount against a threshold if equal, bail if not go back to list appender, etc..

Or if you have a list, you can grab the last item and cycle through similar to above.

Daniel Super Contributor.
Super Contributor.

Re: How to create a loop in HPOO

Thanks guys, I will follow the idea of the list.

But I have one more question. I save/create multiple variables on one Do Nothing step, how can I save on the list?Or its possible to save it altogether?

For example, in the Do Nothing step I have:

hostName1=daniel1
hostIP1=127.0.0.1
hostName2=daniel2
hostIP2=127.0.0.2
hostName3=daniel3
hostIP3=127.0.0.3

Is there any way to add those 3 variables at the same time to the list?

 

0 Likes
AndreiTruta Outstanding Contributor.
Outstanding Contributor.

Re: How to create a loop in HPOO

I suggest to look into: /Library/Utility Operations/Looping as there are some operations that will assist you in the process.

 

Andrei Vasile Truta
0 Likes
AndreiTruta Outstanding Contributor.
Outstanding Contributor.

Re: How to create a loop in HPOO

you could use the list appender from /Library/Utility Operations/Containers/Lists/

 

Andrei Vasile Truta
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.