Details and Options
ResourceFunction["TableWhile"] works like
Table, but supports conditions as criteria for termination.
ResourceFunction["TableWhile"] supports an extended version of the standard iterator specification:
{i,end} | run i from 1 to end in increments of 1 |
{i,start,end} | start from start |
{i,start,end,step} | use increments of step |
{i,{i1,i2,…}} | use successive values i1,i2,… |
{i,{i1,i2,…},conditions} | only continue as long as condition is met |
In all iterator specifications, end can be one of the following:
n | stop when the iteration variable reaches n |
condition | stop when condition[expr] no longer returns True |
{condition,listCondition} | also stop when listCondition[{expr1,expr2,…}] no longer returns True |
{None, listCondition} | use only listCondition |
{n, …} | also stop when the iteration variable reaches n |
ResourceFunction["TableWhile"] uses
NumericQ to distinguish between iteration bounds and conditions. This means that unlike for
Table, symbolic iteration boundaries are not supported.
In the iterator specification {i,{i1,i2,…},conditions}, conditions can be either a single condition or a pair {condition,listCondition}.
In ResourceFunction["TableWhile"][expr,{…,condition,…}], condition is applied to each expression of the resulting list.
In ResourceFunction["TableWhile"][expr,{…,{…,listCondition},…}], listCondition is applied to the list of expressions generated so far at each step.
ResourceFunction["TableWhile"] terminates when either of
condition[…] or
listCondition[…] does not give
True.
When condition[expr] in ResourceFunction["TableWhile"][expr,{i,…,condition,…}] is evaluated, the value of i of the current iteration can also be accessed. The same is true for evaluations of listCondition[{expr1,expr2,…}].
ResourceFunction["TableWhile"][expr,spec1,spec2] is effectively equivalent to ResourceFunction["TableWhile"][ResourceFunction["TableWhile"][expr,spec2],spec1].
ResourceFunction["TableWhile"] effectively uses
Block to localize iterator variables.
ResourceFunction["TableWhile"] accepts the following options:
As long as only numeric iterators are used,
Table[expr,spec1,…] is effectively equivalent to
ResourceFunction["TableWhile"][expr,spec1,…].
As
ResourceFunction["TableWhile"] uses
Do internally, loop control functions such as
Continue,
Break, … might affect the result in ways that are not expected.