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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax for loops

Status
Not open for further replies.

misbrandy

MIS
Jun 12, 2007
41
US
I'm having trouble doing any kind of loop yet I am not getting any syntax errors. I think the loops are not ending where I think. Can you please give me the proper syntax for beginning AND ending a While loop and a For loop and any other kind of loop out there? I typically use Crystal syntax.

As an example I'd want this looped y times (till x reaches y, starting x at zero before):

minimum:=minimum-7
x:=x+1


Using Crystal 10.
 
Here are the loop explanations from the Crystal help file:

The 2 different types of While loops

Type of While Loop

While ... Do
The While ... Do loop evaluates the condition, and if the condition is true, then it evaluates the expression following the Do.

When it has finished doing this, it evaluates the condition again and if the condition is true, it evaluates the expression following the Do again. It continues repeating this process until the condition is false.
While condition Do
expression

Do ... While
The Do ... While loop evaluates the expression once no matter what.

It then evaluates the condition, and if the condition is true, evaluates the expression again. This process continues until the condition is false.
Do
expression
While condition

Note:

The While loops support an Exit While statement to immediately jump out of the loop. Its use is analogous to the use of Exit For in For loops.
As with the For loop, the While loop when considered as an expression always returns the Boolean value True.

The syntax of the For loop through examples

Suppose you want to reverse the {Customer.Customer Name} string. For example, "City Cyclists" becomes "stsilcyC ytiC".

//Reverse a string version 1
Local StringVar str := "";
Local NumberVar strLen :=
Length ({Customer.Customer Name});
Local NumberVar i;
For i := 1 To strLen Do
(
Local NumberVar charPos := strLen - i + 1;
str := str + {Customer.Customer Name}[charPos]
);
str




 
Thank you for the respone, but I saw that and I cannot seem to get the loop to read right. I am either forced to limit it to one line of code (in which case I cannot both do my action(s) and increment my loop counter as well), or I cannot end the loop at all.

Can anyone please give me the exact syntax for a 2+ line of code loop? The ';' or lack thereof are not working. (I wonder if it is my version -- just like trim, truncate, and previous functions which do not work for me.)

eg, if 'numweeks' is 2, I want 'day' to be incremented by 14:

global numbervar day;
local numbervar x;
global numbervar numweeks;
x:=1;
do
day:=day+7;
x:=x+1;
while x<=numweeks;


 
The way to execute more than one statement in a loop is to use parentheses like this:

global numbervar day;
local numbervar x;
global numbervar numweeks;
x:=1;
do
(
day:=day+7;
x:=x+1;
)
while x<=numweeks;
 
Good, that makes at least the one method work...thanks much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top