## Friday, January 7

### A programming problem.

A program:

```     ...
again:n=a();
if (n>0) {
n=b;
goto again;
}
... ```

You know, goto is not a good style in programming. How to get rid of "goto" in this code?
try:
```// wrong program.
do{
n=a();
}while(n>0);
```

Where is "n=b"?

Need Help!

Damon gave a neat solution:

n=a();
while(n>0){
n=b;
n=a();
}
It's very beautiful.

Now my question changed to:
```     ...
again:n=a();
if (n>0) {
n=b;
goto again;
}
else{
n=c();
}
... ```
???

Labels:

At January 09, 2005 1:19 AM, Anonymous said...

again:n=a();
if (n>0) {
n=b;
goto again;
}
else{
n=c();
}

n=c();

n=a();
while(n>0){
n=b;
n=a();
}

At January 10, 2005 10:16 AM, Unknown said...

Actually, "n=a()", "n=b", "n=c()" only mean "Command 1", "Command 2", "Command 3" in the post. I'm thinking of the 流程 of the program, not the detail command.

The last code can be changed as:

n=a();
while(n>0){
n=b;
n=a();
}
n=c();
----------------------
As I said, it means:
...
Command 1;
while (n>0){
Command 2;
Command 1;
}
Command 3;
...