# Class ForeachController

java.lang.Object
org.apache.jmeter.testelement.AbstractTestElement
org.apache.jmeter.control.GenericController
org.apache.jmeter.control.ForeachController

All Implemented Interfaces:
  `Serializable, Cloneable, Controller, Searchable, TestElement, TestCompilerHelper`

public class ForeachController extends GenericController implements Serializable
ForeachController that iterates over a list of variables named XXXX_NN stored in `JMeterVariables` where NN is a number starting from 1 to number of occurences. This list of variable is usually set by PostProcessor (Regexp PostProcessor or `HtmlExtractor`) Iteration can take the full list or only a subset (configured through indexes)

See Also:
  - Serialized Form

## Field Summary

### Fields inherited from class GenericController

`current, subControllersAndSamplers`

### Fields inherited from interface TestElement

`COMMENTS, ENABLED, GUI_CLASS, NAME, TEST_CLASS`

## Constructor Summary

Constructors
Constructor
Description
`ForeachController()`

## Method Summary

Modifier and Type
Method
Description
`String`
`getEndIndexAsString()`
`String`
`getInputValString()`
`protected int`
`getIterCount()`
`String`
`getReturnValString()`
`String`
`getStartIndexAsString()`
`boolean`
`getUseSeparator()`
`protected void`
`incrementLoopCount()`
`void`
`initialize()`
Reset loopCount to Start index
`boolean`
`isDone()`
Indicates whether the Controller is done delivering Samplers for the rest of the test.
`Sampler`
`next()`
Determines the next sampler to be processed.
`protected Sampler`
`nextIsNull()`
Called by `GenericController.next()` when `GenericController.getCurrentElement()` returns `null`.
`protected void`
`reInitialize()`
Resets the controller (called after execution of last child of controller): resetCurrent() (i.e. current=0) increment iteration count sets first=true recoverRunningVersion() to set the controller back to the initial state
`protected void`
`resetLoopCount()`
`void`
`setEndIndex(String endIndex)`
`void`
`setInputVal(String inputValue)`
`void`
`setReturnVal(String inputValue)`
`void`
`setStartIndex(String startIndex)`
`void`
`setUseSeparator(boolean b)`
`void`
`triggerEndOfLoop()`
Trigger end of loop condition on controller (used by Start Next Loop feature)

### Methods inherited from class GenericController

`addIterationListener, addTestElement, addTestElementOnce, currentReturnedNull, fireIterationStart, fireIterEvents, getCurrentElement, getSubControllers, incrementCurrent, incrementIterCount, initializeSubControllers, isFirst, nextIsAController, nextIsASampler, readResolve, reInitializeSubController, removeCurrentElement, removeIterationListener, resetCurrent, resetIterCount, setCurrentElement, setDone, setFirst`

### Methods inherited from class AbstractTestElement

`addPropertiesValues, addProperty, addProperty, canRemove, clear, clearTemporary, clearTestElementChildren, clone, emptyTemporary, equals, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getSearchableTokens, getThreadContext, getThreadName, hashCode, isEnabled, isRunningVersion, isTemporary, logProperties, mergeIn, propertyIterator, recoverRunningVersion, removeProperty, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse, traverseCollection, traverseMap, traverseProperty`

### Methods inherited from class Object

`finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface TestElement

`canRemove, clear, clearTestElementChildren, clone, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getThreadContext, getThreadName, isEnabled, isRunningVersion, isTemporary, propertyIterator, recoverRunningVersion, removeProperty, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse`

## Constructor Details

### ForeachController

public ForeachController()

## Method Details

### setStartIndex

public void setStartIndex(String startIndex)

Parameters:
  `startIndex` - Start index of loop

### getStartIndexAsString

public String getStartIndexAsString()

Returns:
  start index of loop as String

### setEndIndex

public void setEndIndex(String endIndex)

Parameters:
  `endIndex` - End index of loop

### getEndIndexAsString

public String getEndIndexAsString()

Returns:
  end index of loop

### setInputVal

public void setInputVal(String inputValue)

### getInputValString

public String getInputValString()

### setReturnVal

public void setReturnVal(String inputValue)

### getReturnValString

public String getReturnValString()

### setUseSeparator

public void setUseSeparator(boolean b)

### getUseSeparator

public boolean getUseSeparator()

### isDone

public boolean isDone()
Indicates whether the Controller is done delivering Samplers for the rest of the test. When the top-level controller returns true to JMeterThread, the thread is complete.

Specified by:
  `isDone` in interface `Controller`
Overrides:
  `isDone` in class `GenericController`
Returns:
  boolean
See Also:
  - `Controller.isDone()`

### next

public Sampler next()
Description copied from class: `GenericController`

Determines the next sampler to be processed.

If `GenericController.isDone()` is `true`, returns null.

Gets the list element using current pointer. If this is `null`, calls `GenericController.nextIsNull()`.

If the list element is a `Sampler`, calls `GenericController.nextIsASampler(Sampler)`, otherwise calls `GenericController.nextIsAController(Controller)`

If any of the called methods throws `NextIsNullException`, returns `null`, otherwise the value obtained above is returned.

Specified by:
  `next` in interface `Controller`
Overrides:
  `next` in class `GenericController`
Returns:
  the next sampler or `null`

### nextIsNull

protected Sampler nextIsNull() throws NextIsNullException
Called by `GenericController.next()` when `GenericController.getCurrentElement()` returns `null`. Reinitialises the controller.

Overrides:
  `nextIsNull` in class `GenericController`
Returns:
  null (always, for this class)
Throws:
  `NextIsNullException` - when the end of the list has already been reached

### incrementLoopCount

protected void incrementLoopCount()

### resetLoopCount

protected void resetLoopCount()

### getIterCount

protected int getIterCount()

Overrides:
  `getIterCount` in class `GenericController`

### reInitialize

protected void reInitialize()
Resets the controller (called after execution of last child of controller):

- resetCurrent() (i.e. current=0)
- increment iteration count
- sets first=true
- recoverRunningVersion() to set the controller back to the initial state

Overrides:
  `reInitialize` in class `GenericController`

### triggerEndOfLoop

public void triggerEndOfLoop()
Trigger end of loop condition on controller (used by Start Next Loop feature)

Specified by:
  `triggerEndOfLoop` in interface `Controller`
Overrides:
  `triggerEndOfLoop` in class `GenericController`

### initialize

public void initialize()
Reset loopCount to Start index

Specified by:
  `initialize` in interface `Controller`
Overrides:
  `initialize` in class `GenericController`
See Also:
  - `GenericController.initialize()`