Hello everyone
I need to loop to beginneing of routine. Fail to use loop statement.
What can I do ?
Followings are example
#include "hmg.ch"
function main()
Local m_switch:=.F.
if m_switch
Msginfo("Now m_switch is .T."+chr(13)+chr(10)+"Next gonna call inner()")
inner()
else
m_switch:=.T.
Msginfo("Now m_switch is .F."+chr(13)+chr(10)+"Next gonna loop")
loop
endif
return
function inner()
Msginfo("Now in inner(),loop is useable!")
return
What kind statement should I use if I need to loop?
Moderator: Rathinagiri
-
huangchenmin
- Posts: 157
- Joined: Mon Jun 07, 2010 2:24 am
- dhaine_adp
- Posts: 457
- Joined: Wed Aug 06, 2008 12:22 pm
- Location: Manila, Philippines
Re: What kind statement should I use if I need to loop?
Please clarify if you are talking about recursion. You cannot do loops on the sample code that you have provided.
It's either you use do..while or for...next statement or use recursive call.
It's either you use do..while or for...next statement or use recursive call.
Regards,
Danny
Manila, Philippines
Danny
Manila, Philippines
- esgici
- Posts: 4543
- Joined: Wed Jul 30, 2008 9:17 pm
- DBs Used: DBF
- Location: iskenderun / Turkiye
- Contact:
Re: What kind statement should I use if I need to loop?
Hi Chen Minhuangchenmin wrote: I need to loop to beginneing of routine. Fail to use loop statement.
As EXIT statement (opposite in meaning), LOOP statement is usable and meaningful into [DO] WHILE ... ENDDO and FOR ... NEXT loop structure. So it can't be usable out or without of these loop statements structure.
From CL52E Documentation:
Code: Select all
DO WHILE
Execute a loop while a condition is true (.T.)
-------------------------------------------------------------------
Syntax
[DO] WHILE <lCondition>
<statements>...
[EXIT]
<statements>...
[LOOP]
<statements>...
END[DO]
Arguments
<lCondition> is the logical control expression for the DO WHILE
loop.
EXIT unconditionally branches control from within a DO WHILE or
FOR...NEXT structure to the statement immediately following the
corresponding ENDDO or NEXT statement.
LOOP branches control to the most recently executed DO WHILE or FOR
statement.
Description
DO WHILE...ENDDO is a control structure that executes a block of
statements repetitively, as long as <lCondition> evaluates to true (.T.).
When the condition evaluates to true (.T.), control passes into the
structure and proceeds until an EXIT, LOOP, or ENDDO is encountered.
ENDDO returns control to the DO WHILE statement and the process repeats
itself. If an EXIT statement is encountered, control branches to the
nearest ENDDO or NEXT statement. If a LOOP statement is encountered,
control branches to the nearest DO WHILE or FOR statement. If the
condition evaluates to false (.F.), the DO WHILE construct terminates and
control passes to the statement immediately following the ENDDO.
Use EXIT to terminate a DO WHILE structure based on a condition other
than the DO WHILE condition. LOOP, by contrast, prevents execution of
statements within a DO WHILE based on an intermediate condition, and
returns to the most recent DO WHILE statement.
DO WHILE constructs may be nested within any other control structures to
any depth. The only requirement is that each control structure be
properly nested.
Examples
This example demonstrates a typical control structure for a
simple grouped report:
LOCAL cOldSalesman, nTotalAmount
USE Sales INDEX Salesman NEW
DO WHILE .NOT. EOF()
cOldSalesman := Sales->Salesman
nTotalAmount := 0
DO WHILE cOldSalesman = Sales->Salesman ;
.AND. (.NOT. EOF())
? Sales->Salesman, Sales->Amount
nTotalAmount := nTotalAmount + Sales->Amount
SKIP
ENDDO
? "Total: ", nTotalAmount, "for", cOldSalesman
ENDDO
CLOSE Sales
This code fragment demonstrates how LOOP can be used to
provide an intermediate processing condition:
DO WHILE <lCondition>
<initial processing>...
IF <intermediate condition>
LOOP
ENDIF
<continued processing>...
ENDDO
This example demonstrates the use of DO WHILE to emulate a
repeat until looping construct:
LOCAL lMore := .T.
DO WHILE lMore
<statements>...
lMore := (<lCondition>)
ENDDO
This example uses a DO WHILE loop to move sequentially through
a database file:
DO WHILE .NOT. EOF()
<statements>...
SKIP
ENDDOHappy HMG'ing
Regards
--
Esgici
Viva INTERNATIONAL HMG 
-
huangchenmin
- Posts: 157
- Joined: Mon Jun 07, 2010 2:24 am
Re: What kind statement should I use if I need to loop?
Thanks for your supports!dhaine_adp wrote:Please clarify if you are talking about recursion. You cannot do loops on the sample code that you have provided.
It's either you use do..while or for...next statement or use recursive call.
recursion is a good ideal.