Discussion:
declaration before expression
(too old to reply)
Hamed Zahedi
2004-07-03 06:59:11 UTC
Permalink
I understand that a declaration must preceed any statements inside the body of
an SL program, however, do we also have to ensure that this hold true for
statements written inside if-statements, for-loops and while-loops etc?
i.e. which of the following are valid or are they both valid?

begin
// declaration
//statement
for loop
// statement
//declaration
// satement
endfor;
end;

begin
// declaration
//statement
for loop
//declaration
// satement
endfor;
end;

essentially i'm trying to figure out if we can use the same logic inside a
conditional or looping statement (namely "block") as we use within the body of
our code (namely "body")

thanks in advance

Hamed




----------------------------------------
This mail sent through www.mywaterloo.ca
Nguyen Nguyen
2004-07-03 19:13:37 UTC
Permalink
Variable declarations occur at the beginning of the procedure body, before
non-variable declaration statements. You cannot have variable
declarations in the block statements of if_statements, while_statements
etc.

Nguyen
Post by Hamed Zahedi
I understand that a declaration must preceed any statements inside the body of
an SL program, however, do we also have to ensure that this hold true for
statements written inside if-statements, for-loops and while-loops etc?
i.e. which of the following are valid or are they both valid?
begin
// declaration
//statement
for loop
// statement
//declaration
// satement
endfor;
end;
begin
// declaration
//statement
for loop
//declaration
// satement
endfor;
end;
essentially i'm trying to figure out if we can use the same logic inside a
conditional or looping statement (namely "block") as we use within the body of
our code (namely "body")
thanks in advance
Hamed
----------------------------------------
This mail sent through www.mywaterloo.ca
Loading...