MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: strange behavior

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104855] Re: [mg104787] strange behavior
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Thu, 12 Nov 2009 06:00:48 -0500 (EST)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200911101058.FAA19606@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

A similar question was recently asked in this group.

Remember that For returns Null as result, which does not ordinarily get 
displayed.  However, in your second Module, the last two lines of the 
For expression do not have a separating semicolon, and Mathematica keeps 
swallowing line after line until it gets a complete expression it can 
evaluate -- in this case, the product of the result of the ans = 
InputString expression with the Print[ans] result. It's as if you had used:

   Module[{ans=""},
      For[i=1,i<3,i++,
       ans=InputString["Enter a String"] Print[ans]
      ]
   ]

Mathematica is NOT a line-oriented language, but rather an 
expression-oriented language.

Jason Winters wrote:
> Hi!  I am wondering why these two modules behave differently
> 
> 
> Module[{ans = ""},
>   For[i = 1, i < 10, i++,
>     ans = InputString["Enter a String"];
>     Print[ans]
>     ]
>   ]
> 
> 
> and
> 
> 
> Module[{ans = ""},
>   For[i = 1, i < 10, i++,
>     ans = InputString["Enter a String"]
>     Print[ans]
>     ]
>   ]
> 
> 
> One prints out a bunch of extraneous Null's
> 
> Also is there anyway to type variable in Mathematica  i.e. declare i to be and
> integer or string or whatever.
> 
> 
> Thanks for any help you can give.  
> Sorry for the simpleness of these questions.
> 
> Thanks
> 
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: Cumulative probability that random walk variable exceeds
  • Next by Date: Re: kernel crash with integrating the derivative of an
  • Previous by thread: Re: strange behavior
  • Next by thread: Re: strange behavior