* Exit Loop_Statement @ 2000-05-09 0:00 David Freshwater 2000-05-09 0:00 ` Gautier ` (3 more replies) 0 siblings, 4 replies; 13+ messages in thread From: David Freshwater @ 2000-05-09 0:00 UTC (permalink / raw) Hi All, Just a quick question about Exiting a loop. I have an assignment where I have to Exit when "Stop" is input as a clients name, which I can do. The problem is that it has to be case insensitive. Also I am trying to get the exception statement in the Procedure to work to work The Procedure is as follows : --+++++++Buy Procedures+++++++-- --Gets user input and calls on save_data to store procedure Buy is begin I := 0; --Initialize i Nof := 0; --Initialize NOF New_Line; Put("Please enter the name of the file you wish to create : "); Get_Line(Item => Filename, Last => P_L_C_I_F); New_Line; Any_File : Loop Put("Please enter the clients name : "); Get_Line(Item => Any (I + 1).Clients, Last => P_L_C); Put("Olympic Sponsor? (Enter True or False) : "); Boolean_Io.Get(Sponsor); exit Any_File when Any(I+1).Clients(1..3) = "Stop"; I := I + 1; --Increment counter if name<> STOP Skip_Line; Put("Please enter the number of tickets purchased : "); Integer_Io.Get(Item => Any (I + 1).Num_Tickets); Put("Please enter the total cost of purchase : $"); Float_Io.Get(Item => Any (I + 1).Cost_Total); New_Line(3); Skip_Line; end loop Any_File; exception when DATA_ERROR|NUMERIC_ERROR => Put_Line(" *****************************"); New_Line; Put_Line(" * INCORRECT DATA ENTRY ! *"); New_Line; Put_Line(" * Please re-enter the data *"); New_Line; Put_Line(" *****************************"); Skip_Line; New_Line (2); Save_Data(I, Filename, P_L_C_I_F); end Buy; Any help or suggestions would be greatly appreciated. David ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Exit Loop_Statement 2000-05-09 0:00 Exit Loop_Statement David Freshwater @ 2000-05-09 0:00 ` Gautier 2000-05-09 0:00 ` Robert Dewar 2000-05-09 0:00 ` Ken Garlington ` (2 subsequent siblings) 3 siblings, 1 reply; 13+ messages in thread From: Gautier @ 2000-05-09 0:00 UTC (permalink / raw) > exit Any_File when Any(I+1).Clients(1..3) = "Stop"; Look twice at Clients(1..3) and "Stop" How many letters ;-) ? To make insensitive: ... when To_Upper(...) = "STOP" HTH _____________________________________________ Gautier -- http://members.xoom.com/gdemont/ ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Exit Loop_Statement 2000-05-09 0:00 ` Gautier @ 2000-05-09 0:00 ` Robert Dewar 0 siblings, 0 replies; 13+ messages in thread From: Robert Dewar @ 2000-05-09 0:00 UTC (permalink / raw) In article <3917D075.243A3A01@maths.unine.ch>, Gautier <gautier.demontmollin@maths.unine.ch> wrote: > > exit Any_File when Any(I+1).Clients(1..3) = "Stop"; > Look twice at > Clients(1..3) > and > "Stop" > How many letters ;-) ? > To make insensitive: ... when To_Upper(...) = "STOP" > > HTH > _____________________________________________ > Gautier -- http://members.xoom.com/gdemont/ > Right, this Gautier post nicely illustrates what I meant in my previous post. Helpful hints, without giving the solution away. No one wants students to get frustrated, and we all know the frustration of bumping into a bug which due to temporary blindness of temporary loss of whatever it is that makes one able to see things, you cannot find something and need help. We certainly want to provide help to get past such blocks. It's a fine line, and one that is hard to pin down some times, but I think if everyone in CLA who wants to help students posting here makes the effort to think about this line, then we can provide a more useful resource for students (though as I mentioned in another post, it seems to me that the professor involved really *should* be the primary resource). Sent via Deja.com http://www.deja.com/ Before you buy. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Exit Loop_Statement 2000-05-09 0:00 Exit Loop_Statement David Freshwater 2000-05-09 0:00 ` Gautier @ 2000-05-09 0:00 ` Ken Garlington 2000-05-09 0:00 ` John English 2000-05-10 0:00 ` Jeff Creem 3 siblings, 0 replies; 13+ messages in thread From: Ken Garlington @ 2000-05-09 0:00 UTC (permalink / raw) "David Freshwater" <dafresh@cyllene.uwa.edu.au> wrote in message news:8f7oep$khc$1@enyo.uwa.edu.au... > Hi All, > Just a quick question about Exiting a loop. I have an assignment > where I have to Exit when "Stop" is input as a clients name, which I can do. > The problem is that it has to be case insensitive. One typical approach is to convert both sides of the comparison to a known case. > Also I am trying to get > the exception statement in the Procedure to work to work What have you tried? > The Procedure is as follows : Just out of curiosity, does this line cause the loop to exit under *any* conditions? > exit Any_File when Any(I+1).Clients(1..3) = "Stop"; Also, should the loop exit when someone enters sto? How about STOPPER? > I := I + 1; --Increment counter if name<> STOP > > Skip_Line; > Put("Please enter the number of tickets purchased : "); > Integer_Io.Get(Item => Any (I + 1).Num_Tickets); > Put("Please enter the total cost of purchase : $"); > Float_Io.Get(Item => Any (I + 1).Cost_Total); > New_Line(3); > Skip_Line; > > > end loop Any_File; > > exception > > when DATA_ERROR|NUMERIC_ERROR => > > > Put_Line(" *****************************"); > New_Line; > Put_Line(" * INCORRECT DATA ENTRY ! *"); > New_Line; > Put_Line(" * Please re-enter the data *"); > New_Line; > Put_Line(" *****************************"); > Skip_Line; > New_Line (2); > > > Save_Data(I, Filename, P_L_C_I_F); > > end Buy; > > Any help or suggestions would be greatly appreciated. > > David > > ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Exit Loop_Statement 2000-05-09 0:00 Exit Loop_Statement David Freshwater 2000-05-09 0:00 ` Gautier 2000-05-09 0:00 ` Ken Garlington @ 2000-05-09 0:00 ` John English 2000-05-09 0:00 ` Robert Dewar 2000-05-10 0:00 ` Jeff Creem 3 siblings, 1 reply; 13+ messages in thread From: John English @ 2000-05-09 0:00 UTC (permalink / raw) David Freshwater wrote: > procedure Buy is > begin > [...snip...] > Any_File : > Loop > > Put("Please enter the clients name : "); > Get_Line(Item => Any (I + 1).Clients, Last => P_L_C); > Put("Olympic Sponsor? (Enter True or False) : "); > Boolean_Io.Get(Sponsor); > exit Any_File when Any(I+1).Clients(1..3) = "Stop"; That should be Clients(1..4), right? You should convert to e.g. lower case if you want case insensitivity: if Ada.Characters.Handling.To_Lower(Clients(1..4)) = "stop" then ... > [...snip...] > end loop Any_File; > > exception > > when DATA_ERROR|NUMERIC_ERROR => You should really use Constraint_Error instead of Numeric_Error (although they both mean the same thing). Also, don't you want the exception to be handled inside the loop so the user can re-enter the data? At the moment, it'll print an error message, call Save_File, and then you're at the end of the program... Try something like this: loop begin ... exception ... end; end loop; Your exit statement will get you out of the loop; an exception will be handled by the exception handler inside the loop, so after you've handled the exception you'll go round the loop again. HTH, ----------------------------------------------------------------- John English | mailto:je@brighton.ac.uk Senior Lecturer | http://www.it.bton.ac.uk/staff/je Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS ** University of Brighton | -- see http://burks.bton.ac.uk ----------------------------------------------------------------- ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Exit Loop_Statement 2000-05-09 0:00 ` John English @ 2000-05-09 0:00 ` Robert Dewar 2000-05-09 0:00 ` John English 2000-05-09 0:00 ` David Freshwater 0 siblings, 2 replies; 13+ messages in thread From: Robert Dewar @ 2000-05-09 0:00 UTC (permalink / raw) In article <3917C83E.D088C4DF@bton.ac.uk>, John English <je@bton.ac.uk> wrote: > That should be Clients(1..4), right? Well yes, of course, and of course we all saw that. But don't you think it is instructive for people to find a bug like that for themselves. I preferred the previous post which gave a useful pointed hint (think about whether this will ever be true), to this one that provides the correction directly. A hard part of computer programming is figuring out why what you have written does not work, and learning to be careful and avoid writing such things in the first place. Practice is really essential in this task. The purpose of assignments is to provide this practice, and you have to be careful that in an attempt to be helpful you do not bypass this very important function. > You should convert to e.g. lower case if you want case > insensitivity: > if Ada.Characters.Handling.To_Lower(Clients(1..4)) = "stop" > then ... Again, I would point to the reference for this routine, rather than give the exact code, which the student can then just cut and paste without any understanding. Sent via Deja.com http://www.deja.com/ Before you buy. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Exit Loop_Statement 2000-05-09 0:00 ` Robert Dewar @ 2000-05-09 0:00 ` John English 2000-05-09 0:00 ` John English 2000-05-09 0:00 ` David Freshwater 1 sibling, 1 reply; 13+ messages in thread From: John English @ 2000-05-09 0:00 UTC (permalink / raw) Robert Dewar wrote: > In article <3917C83E.D088C4DF@bton.ac.uk>, > John English <je@bton.ac.uk> wrote: > > That should be Clients(1..4), right? > > Well yes, of course, and of course we all saw that. But don't > you think it is instructive for people to find a bug like that > for themselves. I preferred the previous post which gave a > useful pointed hint (think about whether this will ever be > true), to this one that provides the correction directly. I would agree with you completely if the question had been "Why does this code generate a Constraint_Error?" But it wasn't, so I pointed out an unrelated minor typo in passing. Maybe he hit the key next to the 4 by mistake. Maybe it was a deliberate error to generate Constraint_Error for testing purposes. > A hard part of computer programming is figuring out why what > you have written does not work, and learning to be careful > and avoid writing such things in the first place. Practice > is really essential in this task. The purpose of assignments > is to provide this practice, and you have to be careful that > in an attempt to be helpful you do not bypass this very > important function. I know you don't like people giving direct answers to questions, but I hadn't realised this also extended to questions that haven't even been asked... ----------------------------------------------------------------- John English | mailto:je@brighton.ac.uk Senior Lecturer | http://www.it.bton.ac.uk/staff/je Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS ** University of Brighton | -- see http://burks.bton.ac.uk ----------------------------------------------------------------- ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Exit Loop_Statement 2000-05-09 0:00 ` John English @ 2000-05-09 0:00 ` John English 2000-05-09 0:00 ` Robert Dewar 0 siblings, 1 reply; 13+ messages in thread From: John English @ 2000-05-09 0:00 UTC (permalink / raw) John English wrote: > I would agree with you completely if the question had been "Why > does this code generate a Constraint_Error?" Just before Robert roasts me again, let me point out that my talking about Constraint_Error was due misremembering the original code as involving an assignment Clients(1..3) := "Stop". I've just revisited the code and now I'm going to go and wipe the egg off my face. ----------------------------------------------------------------- John English | mailto:je@brighton.ac.uk Senior Lecturer | http://www.it.bton.ac.uk/staff/je Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS ** University of Brighton | -- see http://burks.bton.ac.uk ----------------------------------------------------------------- ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Exit Loop_Statement 2000-05-09 0:00 ` John English @ 2000-05-09 0:00 ` Robert Dewar 0 siblings, 0 replies; 13+ messages in thread From: Robert Dewar @ 2000-05-09 0:00 UTC (permalink / raw) In article <39182781.C1780175@bton.ac.uk>, John English <je@bton.ac.uk> wrote: > Just before Robert roasts me again, let me point out that my talking > about Constraint_Error was due misremembering the original code as > involving an assignment Clients(1..3) := "Stop". I've just revisited > the code and now I'm going to go and wipe the egg off my face. Right, and that's why I thought the hint "will this ever be true?" was an appropriate one :-) Sent via Deja.com http://www.deja.com/ Before you buy. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Exit Loop_Statement 2000-05-09 0:00 ` Robert Dewar 2000-05-09 0:00 ` John English @ 2000-05-09 0:00 ` David Freshwater 2000-05-09 0:00 ` DuckE 1 sibling, 1 reply; 13+ messages in thread From: David Freshwater @ 2000-05-09 0:00 UTC (permalink / raw) Hi, Thanks for the help....I had picked up the (1..3) error. I actually have written 2 programs for this assignment. One works well, the other is a different approach to what we have been taught. Let me point out that I am an external student studying this, which makes it hard as I don't have any one to bounce ideas off or get any helpful input. So any help whether pointers or snippets of code are really appreciated. I do understand the need to do this by myself but it just gets frustrating. David Robert Dewar <robert_dewar@my-deja.com> wrote in message news:8f91ps$vb3$1@nnrp1.deja.com... > In article <3917C83E.D088C4DF@bton.ac.uk>, > John English <je@bton.ac.uk> wrote: > > That should be Clients(1..4), right? > > Well yes, of course, and of course we all saw that. But don't > you think it is instructive for people to find a bug like that > for themselves. I preferred the previous post which gave a > useful pointed hint (think about whether this will ever be > true), to this one that provides the correction directly. > > A hard part of computer programming is figuring out why what > you have written does not work, and learning to be careful > and avoid writing such things in the first place. Practice > is really essential in this task. The purpose of assignments > is to provide this practice, and you have to be careful that > in an attempt to be helpful you do not bypass this very > important function. > > > You should convert to e.g. lower case if you want case > > insensitivity: > > if Ada.Characters.Handling.To_Lower(Clients(1..4)) = "stop" > > then ... > > Again, I would point to the reference for this routine, rather > than give the exact code, which the student can then just cut > and paste without any understanding. > > > > > Sent via Deja.com http://www.deja.com/ > Before you buy. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Exit Loop_Statement 2000-05-09 0:00 ` David Freshwater @ 2000-05-09 0:00 ` DuckE 0 siblings, 0 replies; 13+ messages in thread From: DuckE @ 2000-05-09 0:00 UTC (permalink / raw) "David Freshwater" <dafresh@odyssey.apana.org.au> wrote in message news:39181473@news.wa.apana.org.au... > Hi, > Thanks for the help....I had picked up the (1..3) error. > I actually have written 2 programs for this assignment. One works well, the > other is a different approach to what we have been taught. Let me point out > that I am an external student studying this, which makes it hard as I don't > have any one to bounce ideas off or get any helpful input. So any help > whether pointers or snippets of code are really appreciated. > I do understand the need to do this by myself but it just gets frustrating. > For validating data entry it is sometimes convenient to use a loop that will not exit until a valid entry is made: ReadLoop: loop begin Put( "Enter Value > " ); Get( value ); exit ReadLoop when value >= 1 and value <= 10; exception when others => null; end; Put_Line( "Invalid Entry - please enter a value between 1 and 10" ); end loop; I hope this helps, SteveD ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Exit Loop_Statement 2000-05-09 0:00 Exit Loop_Statement David Freshwater ` (2 preceding siblings ...) 2000-05-09 0:00 ` John English @ 2000-05-10 0:00 ` Jeff Creem 2000-05-10 0:00 ` Robert A Duff 3 siblings, 1 reply; 13+ messages in thread From: Jeff Creem @ 2000-05-10 0:00 UTC (permalink / raw) By the way...Not that this was the original question and it is probably help "out of scope" but so manner programmers (even those who have been doing it for a living for a few years) do this that I thought it worth while to catch this now.. Take a look at the following snippet of code.. > I := 0; --Initialize i > Nof := 0; --Initialize NOF > After reading the comments, is there anything that you now know that you did not know before you read the comments....Nope....Just a case of commenting so that one can feel good that there are comments in the code...Use better variable names and delete those comments...(Of course there are other more subtle things that could be done on those lines as well but that is left as an exercise for the writer) Jeff ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Exit Loop_Statement 2000-05-10 0:00 ` Jeff Creem @ 2000-05-10 0:00 ` Robert A Duff 0 siblings, 0 replies; 13+ messages in thread From: Robert A Duff @ 2000-05-10 0:00 UTC (permalink / raw) "Jeff Creem" <jcreem@atetola.mv.com> writes: > Take a look at the following snippet of code.. > > > I := 0; --Initialize i > > Nof := 0; --Initialize NOF > > After reading the comments, is there anything that you now know that you did > not know before you read the > comments....Nope.... Well, I wouldn't expect to see comments like that in professionally-written code, but I don't think it's so bad for a beginner to write comments like that. Somebody who doesn't know how to program, and/or doesn't know the programming language they're using very well, can benefit from comments that remind them of the language semantics. Once they learn the language well, they can easily learn to write better comments. It's easier than *not* commenting early on, and then later learning to do so. By the way, here's an example of the kind of comments you're complaining about. This comes from an ACATS test, which is testing the pragma Import feature for interfacing Ada code and C code. It's so bad that I think the author of this code must have been doing it as a joke. I mean, it's got one simple line of executable code, and several paragraphs explaining in detail how it works! /* -- CD30051.C -- -- Grant of Unlimited Rights -- -- Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687 and -- F08630-91-C-0015, the U.S. Government obtained unlimited rights in the -- software and documentation contained herein. Unlimited rights are -- defined in DFAR 252.227-7013(a)(19). By making this public release, -- the Government intends to confer upon all recipients unlimited rights -- equal to those held by the Government. These rights include rights to -- use, duplicate, release or disclose the released technical data and -- computer software in whole or in part, in any manner and for any purpose -- whatsoever, and to have or permit others to do so. -- -- DISCLAIMER -- -- ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR -- DISCLOSED ARE AS IS. THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED -- WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE -- SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE -- OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A -- PARTICULAR PURPOSE OF SAID MATERIAL. --* -- -- FUNCTION NAME: _cd3005_1 -- -- FUNCTION DESCRIPTION: -- This C function returns the sum of its parameter and 1 through -- the function name. The parameter is unchanged. -- -- INPUTS: -- This function requires that one parameter, of type int, be passed -- to it. -- -- PROCESSING: -- The function will calculate the sum of its parameter and 1 -- and return this value as the function result through the function -- name. -- -- OUTPUTS: -- The sum of the parameter and 1 is returned through function name. -- -- CHANGE HISTORY: -- 12 Oct 95 SAIC Initial prerelease version. -- 14 Feb 97 PWB.CTA Created this file from code appearing in -- CD30005.A (as comments). --! */ int _cd30005_1( Value ) { /* int Value */ return Value + 1; } ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2000-05-10 0:00 UTC | newest] Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2000-05-09 0:00 Exit Loop_Statement David Freshwater 2000-05-09 0:00 ` Gautier 2000-05-09 0:00 ` Robert Dewar 2000-05-09 0:00 ` Ken Garlington 2000-05-09 0:00 ` John English 2000-05-09 0:00 ` Robert Dewar 2000-05-09 0:00 ` John English 2000-05-09 0:00 ` John English 2000-05-09 0:00 ` Robert Dewar 2000-05-09 0:00 ` David Freshwater 2000-05-09 0:00 ` DuckE 2000-05-10 0:00 ` Jeff Creem 2000-05-10 0:00 ` Robert A Duff
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox