# Clear inside a loop

I want to solve a system of differential equations and each time I want to change two parameters. To prevent wrong result I want to clear every assignment after solving the equations in each iteration. I have a Do-loop with two iterator. The problem is that if I use Clear["Global*"] then the outer iterator will not be accessible to the code inside the loop.

Here is an example:

Do[{Print[a]; Clear["Global*"];}, {a, 1, 2}, {b, 1, 2}]

Result:

1

a

2

a

As you can see the iterator a is erased for the inner iterator b. How can I resolve this issue?

I expect the outer iterator to be printed each time. There are 4 iteration in total, so I expect to get:

1
1
2
2

I want both iterators, a and b, in spite of using Clear command to be accessible to the code inside loop. I want to clear everything after each iteration except iterators a and b.

• What would be your expected result? – Öskå Jul 1 '14 at 10:04
• I edited the post. – MOON Jul 1 '14 at 10:09
• Perhaps a description and removal of the actual symbol clash would be more effective than dropping the big one. Posting the offending code is often useful. – Yves Klett Jul 1 '14 at 10:27

Map[Clear, DeleteCases[Names["Global*"], "a" | "b"]]},