* procedures and return
@ 2004-08-16 6:23 zork
2004-08-16 6:48 ` Puckdropper
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: zork @ 2004-08-16 6:23 UTC (permalink / raw)
Hi,
I am a little confused about how precedures handle a 'return' statement. I
have the following:
procedure my_procedure (...)
begin
if <some_condition> then
put("inside if-statement);
new_line;
return;
end if;
put ("outside if-statement");
end my_procedure;
I am finding that if some_condition *is* satisfied, then the procedure
prints both put statements i.e.
inside if-statement
outside if-statement
... i thought 'return' should exit the procedure and return control to where
the procedure was called. hence only printing "inside if-statement"?
I am using ada95.
Any help appreciated!
zork
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: procedures and return
2004-08-16 6:23 procedures and return zork
@ 2004-08-16 6:48 ` Puckdropper
2004-08-16 7:10 ` zork
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Puckdropper @ 2004-08-16 6:48 UTC (permalink / raw)
zork wrote:
> Hi,
>
> I am a little confused about how precedures handle a 'return' statement. I
> have the following:
>
> procedure my_procedure (...)
> begin
> if <some_condition> then
> put("inside if-statement);
> new_line;
> return;
> end if;
> put ("outside if-statement");
> end my_procedure;
>
> I am finding that if some_condition *is* satisfied, then the procedure
> prints both put statements i.e.
>
> inside if-statement
> outside if-statement
>
> ... i thought 'return' should exit the procedure and return control to where
> the procedure was called. hence only printing "inside if-statement"?
>
> I am using ada95.
>
> Any help appreciated!
>
> zork
>
>
I'm just a beginner, but it would seem what you want to do could be (and
is more easily accomplished by) using an if...then...else statement.
---Code:---
procedure my_procedure (...)
begin
if <some_condition> then
put("inside if-statement);
new_line;
else
Ada.Text_IO.put("outside if-statement");
end if;
end my_procedure;
---end code---
Puckdropper
--
www.uncreativelabs.net
Old computers are getting to be a lost art. Here at Uncreative Labs, we
still enjoy using the old computers. Sometimes we want to see how far a
particular system can go, other times we use a stock system to remind
ourselves of what we once had.
To email me directly, send a message to puckdropper (at) fastmail.fm
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: procedures and return
2004-08-16 6:23 procedures and return zork
2004-08-16 6:48 ` Puckdropper
@ 2004-08-16 7:10 ` zork
2004-08-16 9:50 ` Georg Bauhaus
2004-08-16 11:03 ` Gautier
3 siblings, 0 replies; 5+ messages in thread
From: zork @ 2004-08-16 7:10 UTC (permalink / raw)
Oh please disregard this post!
"zork" <zork@nospam.com> wrote in message
news:412052f5$1@dnews.tpgi.com.au...
> Hi,
>
> I am a little confused about how precedures handle a 'return' statement. I
> have the following:
>
> procedure my_procedure (...)
> begin
> if <some_condition> then
> put("inside if-statement);
> new_line;
> return;
> end if;
> put ("outside if-statement");
> end my_procedure;
>
> I am finding that if some_condition *is* satisfied, then the procedure
> prints both put statements i.e.
>
> inside if-statement
> outside if-statement
>
> ... i thought 'return' should exit the procedure and return control to
where
> the procedure was called. hence only printing "inside if-statement"?
>
> I am using ada95.
>
> Any help appreciated!
>
> zork
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: procedures and return
2004-08-16 6:23 procedures and return zork
2004-08-16 6:48 ` Puckdropper
2004-08-16 7:10 ` zork
@ 2004-08-16 9:50 ` Georg Bauhaus
2004-08-16 11:03 ` Gautier
3 siblings, 0 replies; 5+ messages in thread
From: Georg Bauhaus @ 2004-08-16 9:50 UTC (permalink / raw)
zork <zork@nospam.com> wrote:
:
: procedure my_procedure (...)
is
: begin
: if <some_condition> then
: put("inside if-statement);
: new_line;
: return;
: end if;
: put ("outside if-statement");
: end my_procedure;
There are only two Boolean values. You can try to write
a procedure like the above with very little changes so it can
be compiled as a main program. Use True for one compilation,
False for another, and see what happens.
Anything but return on "return" should be very surprising.
Are you sure that "outside if-statement" is uttered by my_procedure
and not from somewhere else?
Georg
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: procedures and return
2004-08-16 6:23 procedures and return zork
` (2 preceding siblings ...)
2004-08-16 9:50 ` Georg Bauhaus
@ 2004-08-16 11:03 ` Gautier
3 siblings, 0 replies; 5+ messages in thread
From: Gautier @ 2004-08-16 11:03 UTC (permalink / raw)
zork:
> I am a little confused about how precedures handle a 'return' statement. I
> have the following:
>
> procedure my_procedure (...)
> begin
> if <some_condition> then
> put("inside if-statement);
> new_line;
> return;
> end if;
> put ("outside if-statement");
> end my_procedure;
>
> I am finding that if some_condition *is* satisfied, then the procedure
> prints both put statements i.e.
>
> inside if-statement
> outside if-statement
>
> ... i thought 'return' should exit the procedure and return control to where
> the procedure was called. hence only printing "inside if-statement"?
Aren't you calling 'my_procedure' twice, once with <some_condition> = True,
then once with <some_condition> = False ?
________________________________________________________
Gautier -- http://www.mysunrise.ch/users/gdm/gsoft.htm
NB: For a direct answer, e-mail address on the Web site!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-08-16 11:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-16 6:23 procedures and return zork
2004-08-16 6:48 ` Puckdropper
2004-08-16 7:10 ` zork
2004-08-16 9:50 ` Georg Bauhaus
2004-08-16 11:03 ` Gautier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox