Postion and variable in a list

Hi all,
Short q.

The attached image seems to show something simple - If a certain condition does not apply
Remove the item from a list - However i am not sure i get it right
In the first part of the IF statement i ask if a certain string of text contain the value from “J”
If true - All good
But when i come to the second part i say that if the above is NOT true
“J” Should be removed from list

This second time, i am referring to the item “J” as an item - Meaning a position in the list, should be removed as the Content of this item number does not comply with the first statement.
sometimes J refers to the position in the list - and
sometimes J refers to the value it self.

So how shall i think doing this operation ?
@tatiang - Any ideas… @ioannis ??

There are two ways to loop through a list:

  1. Use the Count with from 1 to ____ block. The variable “j” represents an integer and can be used as a list item index #.

  2. Use the For each item in list block. The variable “j” represents a list item. You will need to use a different variable and manually increment it by adding 1 during each loop iteration. Use that second variable as the list item index #.

Thanks :smiley: But sorry Tatiang… You lost me there…
I am after a “For Each” operation and check the value behind each #item

Lets say list with items as follows
1 = Banana
2 = Apple
3 = Pear
4 = Orange

Using For Each for List X i should expect

  1. If Banana exist in another string of text - And it is - Good, then let “Banana” remain in list
  2. If Apple exist in another string of text - And it is - Good, then let “Apple” remain in list
  3. If Pear exist in another string of text - And it is NOT - Sorry, then “Pear” should NOT remain in list
    so i then use From List X - Remove item 3
    And then i expect the “For Each” operation to continue…
    How can i achieve that…?

Create a variable called loopCount. Set it to 0 above the loop block. Inside the loop, change it by 1. For your in list remove block, use loopCount instead of j.

Do you mean that J does allways, and without exception refers to the content…
rather than item and items number?

When you use a For each item block, j only and always refers to the list item’s value.

So if you loop through the list {“A”, “B”, “C”}, the second time through the list, j will have the value “B”. It will never have the value 2, for example.

1 Like