home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!spool.mu.edu!agate!apple!mumbo.apple.com!gallant.apple.com!kip2-42.apple.com!user
- From: jpugh@apple.com (Jon Pugh)
- Newsgroups: comp.sys.mac.hypercard
- Subject: Re: Initializing HC variables
- Message-ID: <jpugh-191292115205@kip2-42.apple.com>
- Date: 19 Dec 92 20:03:29 GMT
- References: <7183@ucsbcsl.ucsb.edu>
- Sender: news@gallant.apple.com
- Followup-To: comp.sys.mac.hypercard
- Organization: Apple Computer, Inc.
- Lines: 51
-
- In article <7183@ucsbcsl.ucsb.edu>, sekey@engrhub.ucsb.edu (Andrew Sekey)
- wrote:
- >
- >
- > Suppose we have an array of variables x1, x2, x3, etc, and we want to
- > initialize them to zero, i.e. to set:
- >
- > x1 = 0; x2 = 0, ........xN = 0.
- >
- > Can this be done in a "repeat" structure?
- >
- > (What would be obvious in e.g. Fortran, does not work:
- >
- > repeat with j = 0 to N
- > put 0 into x & j
- > end repeat
- >
- > since even including a line 'put x & j into dummy', when followed by
- > 'put 0 into dummy', will only change 'dummy', not xj.)
-
- This is an ideal use of the DO command.
-
- repeat with i = 0 to n
- do "put 0 into x" & i
- end repeat
-
- This allows you to execute any string you can build as a Hypertalk command.
- The only drawback is that it can't be compiled, but that's not much of a
- penalty given the effeciency of Hypertalk's compiler. ;)
-
- Here's a help script I wrote to place the name of a field into the field
- while saving its contents in a global. This assumes the field names are
- single words which are legal variable names.
-
- repeat with i = 1 to number of flds
- do "global" && short name of fld i
- do "put fld" && i && "into" && short name of fld i
- end repeat
-
- -- and then to restore
-
- repeat with i = 1 to number of flds
- do "global" && short name of fld i
- do "put" && short name of fld i && "into fld" && i
- do "put" && quote & quote && "into fld" && i
- end repeat
-
- Mind you, balloon help is better than this technique, but I think this
- shows how to use the do command quite nicely.
-
- Jon
-