Question: I want to print all non-zero answers to an array so I can then print them to a file. 

```
result = {};
nothing = 0;
For[i = 0, i < 6, i++,
 s = SquaresR[2, i]
    If[s == 0, nothing , AppendTo[result, {i, s}]];]
result

```

What I end up getting is an empty array.

Answer: 
You can use the fact that `SquaresR` is `Listable` in its second argument and then `DeleteCases` to get rid of zeros.

```
DeleteCases[
 Transpose[{#, SquaresR[2, #]} &@Range[0, 5]],
 {_, 0}]
(* {{0, 1}, {1, 4}, {2, 4}, {4, 4}, {5, 8}} *)

```

Also, appending repeatedly to an array in a loop is a major performance pitfall. However, while it's probably not the best approach in this case, you may need to build a collection in a loop, and an `Association` is a pretty efficient way to do that. At the end, you can use `Keys`, `Values`, or `KeyValueMap` to turn the answer into a list, if you need that:

```
Module[{result = <||>},
 Do[With[{s = SquaresR[2, i]},
   If[s != 0,
    AssociateTo[result, i -> s]]],
  {i, 0, 5}];
 KeyValueMap[List, result]]
(* {{0, 1}, {1, 4}, {2, 4}, {4, 4}, {5, 8}} *)

```
```
result = If[s = SquaresR[2, #]; s == 0, Nothing, {#, s}] & /@ Range[0, 5]

```