Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question on Clipper 87 2

Status
Not open for further replies.

BelgianBrownie

Programmer
Feb 22, 2005
16
BE
Hello one and all. It's a long story that I will not go into, but after not programming since 1989, I have taken on the maintenance of a bespoke system for a small business in my area.

The system is written in Clipper Summer 87, a language that I have never seen before! I am making some good progress, but I have a "dumb" question to ask about the "DO CASE" command.

There is a piece of code like this:

DO CASE
CASE....

CASE....

CASE....
EXIT
variable=1
ENDCASE

My question is, as there is no OTHERWISE, when all CASE tests are false, will the program drop to ENDCASE or perform the "variable=1" statement? In other words, is there an implied "otherwise"?

Many thanks in advance.
 
If no CASEs are true and there is no otherwise then control just passes to the next statement after ENDCASE.

I don't this the variable=1 line will ever be executed because the preceding EXIT statement will force it to ENDCASE.

Jock
 
Jock

Thanks a lot. That is exactly as I read it as well. I am picking up some old code here and the person who wrote it was supposed to be an expert in Clipper! This is why I questioned it.

Another strange one, there is some code which contains a FOR... NEXT statement. However, after the NEXT, there are a few statements then a LOOP. According to the syntax on the Norton Guide, the LOOP option should be before the NEXT. Am I correct?

If this is the case, would the LOOP statement cause control to be directed to the previous FOR... NEXT that was executed?

Thanks in advance,

Confused of Belgium!
 

If you see LOOP after FOR... NEXT statement, it should belong to some outer loop, that surrounds that FOR... NEXT (either another FOR... NEXT, or DO WHILE).

LOOP will not go to the top of the previous FOR... NEXT that was already executed, it will go to the top of the nearest loop within which it is located.

So look for an outer loop of any kind.
 
Stella740pl,

Thanks. There is a main controlling "DO WHILE .T.". I guess it was the programmer's way of saying "that's it" and returning to the main program loop (a "go to", in my old cobol terminology!!). May not have been my method of choice of doing things.

There are about 20,000 lines of code in the system, and only about a dozen comments amongst them (plus NO documentation)! So I am doing a lot of "detective" work. Well, the client knows the score and is happy to pay me to learn all this :)

Thanks for your help.
 

BelgianBrownie,

Something bothered me about your previous question, and I just realized what.

I used Clipper Summer '87 in early 90's, and didn't touch it since then. But I work in FoxPro/Visual FoxPro most of the time since then, and they are pretty close, so I believe it would be the same in Clipper - at least as far as I remeber.

EXIT controls loops, and DO CASE is not a loop. EXIT wouldn't take you just out of DO CASE, to the next statement after ENDCASE. EXIT will force you out of the innermost loop within which it is located (in your case, I think, it would be out of your main controlling DO WHILE .T., or to the end of the procedure).

This DO WHILE .T. - LOOP/EXIT is not just your original programmer's way to do things, it's a well known trick to do things since GO TO style of programming went out of vogue, so to say. In some cases there are better choices, but not always. If your DO WHILE .T. doesn't have other EXITs, there is no way out of this loop. So this is probably the one.
 
Stella740pl,

I see what you are saying. As it happens, the next statement after the ENDCASE just happens to be the ENDDO of the "master" loop, the "DO WHILE .T.".

There are other EXITS in the main loop, by the way.

A short and very simplified view of what I have is:
DO WHILE .T.
DO CASE
CASE....

CASE....

CASE....
EXIT
variable=1
ENDCASE
ENDDO
RETURN

If no case is true, would control pass back to the main loop or would it in fact end the main loop through the RETURN statement?

Either way, variable=1 will never be actioned!

Thanks.
 
Sorry (it's getting late and I am getting tired!).

If no case is true then control will drop through to the ENDDO. If the last case is true, it will EXIT.

That's correct, isn't it?

thanks.
 

If no case is true, then control will drop through ENDCASE to the ENDDO - and then return to the beginning of DO WHILE. It will go rounds within DO WHILE until it meets an EXIT statement.

(You know that DO WHILE .T. on intself is an endless loop, right? In general case, DO WHILE <logical expression> is executed while the <logical expression>=.T., and the comparison is done in the beginning of the loop.)

If the last case is true, EXIT will pass control to the next statement after ENNDO - straight to RETURN statement and out of this procedure, in your case.

It looks like variable=1 is never used.

Stella

 
Stella

Thanks for the confirmation.

I used to programme in TAL (Tandem language), but that was in the 1980s! Similar constructs exist in TAL (DO WHILE true...), so indeed I am familiar with such concepts. However, I do need confirmation of the nuances of Clipper, and seeing code such as "the variable=1" does make me double-check things as I would not have expected to find such blatant redundant code!

Thanks again.

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top