Search code examples
functionloopsnullwolfram-mathematicawolfram-language

Why I am I getting Null in my Mathematica function?


I have made a function with mathematica and Im getting what I want from it however I am also getting 'Null' on the end and im not sure why.

Here is my code:

x = ""
ButterflyString[y_]:=For[i = 1, i < 8, i++, x = StringTake[y, {i}] <> x] x

My input:

ButterflyString["Wolfram"]

My output:

marfloW Null

Solution

  • As @Bill posted in the comments:

    x = "";
    ButterflyString[y_] :=
     (For[i = 1, i < 8, i++, x = StringTake[y, {i}] <> x];
      x)
    

    This worked for me.