Array issue

Vdevmat33
Tera Contributor

I have a transform script where i am using multiple arrays but the final array is not printing the expected output.

When i check in logs i can see the same value is printing multiple times. i have a combination of for and if loop, i believe the reason may be i am using the wrong combination. How do we generally use combination of for if and else? A structure could be provided would be helpful. Thanks in advance!

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

 I believe you you are using it as below:-

 

for()
{
if()
//some line of code
}
else
{
//some line of code
}
}

 

because of which for every for loop if the if fails it iterates to else and hence the else maybe pushing multiple values in array.

 

You should consider using it as below:-

 

if()
{
for()
//some line of code
}
else
{
//some line of code
}

 

Please mark my answer as correct based on Impact. 

View solution in original post

3 REPLIES 3

palanikumar
Mega Sage

Hi,

Combination of Loop is always a problem. There is no guidelines to this as the combination changes based on your expected data format and we cant control. I can suggest if you can share the script

Thank you,
Palani

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

 I believe you you are using it as below:-

 

for()
{
if()
//some line of code
}
else
{
//some line of code
}
}

 

because of which for every for loop if the if fails it iterates to else and hence the else maybe pushing multiple values in array.

 

You should consider using it as below:-

 

if()
{
for()
//some line of code
}
else
{
//some line of code
}

 

Please mark my answer as correct based on Impact. 

Vdevmat33
Tera Contributor

Thanks! This combination worked!