Skip to main content
General cleanup
Source Link
m_goldberg
  • 108.6k
  • 16
  • 107
  • 263

Output always returns NULL Function returning Null along with other unexpected expressions

When I use some function, at the end along with the output I get some NULLs returned that I don't understand the reason for and are highly undesirable. For example, inwhen I define the reversal of list with

ReverseList[ele_List] := Module[{list = List[], i, k = 1}, {For[i = Length[ele], i > 0, {i--, k++}, {AppendTo[list, ele[[i]]]}], Print[list], Return[list]} ] 

The output I get

 ReverseList[{1, 2, 3, 4, 5}] 

is

{5,4,3,2,1} {Null, Null, Return[{5, 4, 3, 2, 1}]} 

I am also facinghave a problem with returning the list. Can someone please help me with these two problems I am facing.?

Output always returns NULL along

When I use some function, at the end along with the output I get some NULLs returned that I don't understand the reason for and are highly undesirable. For example, in reversal of list

ReverseList[ele_List] := Module[{list = List[], i, k = 1}, {For[i = Length[ele], i > 0, {i--, k++}, {AppendTo[list, ele[[i]]]}], Print[list], Return[list]} ] 

The output I get is

{5,4,3,2,1} {Null, Null, Return[{5, 4, 3, 2, 1}]} 

I am also facing problem with returning list. Can someone please help me with these two problems I am facing.

Function returning Null along with other unexpected expressions

When I use some function, at the end along with the output I get some NULLs returned that I don't understand the reason for and are highly undesirable. For example, when I define the reversal of list with

ReverseList[ele_List] := Module[{list = List[], i, k = 1}, {For[i = Length[ele], i > 0, {i--, k++}, {AppendTo[list, ele[[i]]]}], Print[list], Return[list]} ] 

The output I get

 ReverseList[{1, 2, 3, 4, 5}] 

is

{5,4,3,2,1} {Null, Null, Return[{5, 4, 3, 2, 1}]} 

I am also have a problem with returning the list. Can someone please help me with these two problems?

Source Link
Pankaj Sejwal
  • 2.1k
  • 14
  • 24

Output always returns NULL along

When I use some function, at the end along with the output I get some NULLs returned that I don't understand the reason for and are highly undesirable. For example, in reversal of list

ReverseList[ele_List] := Module[{list = List[], i, k = 1}, {For[i = Length[ele], i > 0, {i--, k++}, {AppendTo[list, ele[[i]]]}], Print[list], Return[list]} ] 

The output I get is

{5,4,3,2,1} {Null, Null, Return[{5, 4, 3, 2, 1}]} 

I am also facing problem with returning list. Can someone please help me with these two problems I am facing.