Re: GoTo between different cell
- To: mathgroup at smc.vnet.net
- Subject: [mg59449] Re: GoTo between different cell
- From: albert <awnl at arcor.de>
- Date: Wed, 10 Aug 2005 02:55:56 -0400 (EDT)
- References: <dd9ngj$j2h$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi Ramiro,
> Therefore, also if it seems a quite prehistoric idea, I want to break my
> computation in many cells and to back N times to a certain cell to
> evaluate them, something like the GoTo function but between different cell
> (perhaps tagged).
you could use the Function SelectionMove, NotebookFind and
SelectionEvaluateCreateCell along with CellTags to do what you want, but I
would strongly recommend to reorganize your code instead, especially if you
find it hard to debug/check if everything goes right...
Try to identify parts of code in your do-loop that can be functions of their
own and put these functions into extra cells. This doesn't cause more
trouble than defining celltags in mathematica: a simple first step would be
to define single blocks of code (whatever you would like to put into single
cells anyway) in your do-loop and define "functions" like these (without
the need to use any local variables, arguments and such, even the empty
brackets after block1 are just a matter of taste):
block1[]:=(
first part of your code goes here.
)
this can of course go in a single cell. Then your do-loop could look
something like:
Do[
block1[];
If[condition1,
block2[],
block3[]
]
block4[];
]
,{i,1,100}]
Of course it makes sense to find more descriptive names than blocki etc. to
make the code easier to understand, but that's up to you. I have a strong
feeling that you might have a lot of redundancy in your code "blocks" which
you can reduce by such an approach and even more with the next step: try to
use local variables wherever possible and use arguments to pass values
around, instead of working with just global variables, but maybe that's not
even necessary to "just get a result"...
> I know that sounds quite old but it is what I need.
good programming style is not a matter of age (of neither programmer nor
language) :-).
Albert