From: Trish Cayetano <trishacayetano@gmail.com>
Subject: Re: Error "exception not permitted here" when putting EXCEPTION in a loop
Date: Sat, 18 Jul 2015 05:41:52 -0700 (PDT)
Date: 2015-07-18T05:41:52-07:00 [thread overview]
Message-ID: <f6160b36-25b7-4200-9739-b92e29557903@googlegroups.com> (raw)
In-Reply-To: <mod8dl$i5e$1@dont-email.me>
On Saturday, July 18, 2015 at 6:07:12 PM UTC+8, björn lundin wrote:
> On 2015-07-18 10:14, Trish Cayetano wrote:
>
> e is my own code (i removed the functions and others)... S
>
> orry I am really new to Ada. I actually tried also to put
>
> another loop and added declare, begin and end. It
>
> hang after I ran. And when I terminated the process, it looks like it
> ran infinitely in loops.
> >
>
> when you set endGame to true,
> you are in the *inner* loop.
> but the *outer* loop tests for endGame.
>
> How do you exit the *inner* loop?
>
> what purpose has the *inner* loop?
>
> When you have the answer,
> your program will be easy to fix.
>
> --
> Björn
Hello Björn,
I don't need the inner loop after all.
I removed the inner loop but it still run in infinite loops.
REVISED CODE:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Numerics.Discrete_Random;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO;
with Ada.IO_Exceptions; use Ada.IO_Exceptions;
procedure Main is
GuessWord : String(1..20);
last: Natural;
option : Integer := 0;
endGame: Boolean := False;
begin
while not endGame loop
begin
Ada.Text_IO.Put_Line(" | CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit ");
Ada.Integer_Text_IO.Get(option);
case option is
when 1 =>
Ada.Text_IO.Put_Line("Shuffle");
when 2 =>
Ada.Text_IO.Put_Line("Pass");
when 3 =>
Skip_Line;
Ada.Text_IO.Put_Line("Enter word: ");
Ada.Text_IO.Get_Line(GuessWord, Last);
when 4 =>
Ada.Text_IO.Put_Line("See you again soon!");
endGame := true;
when others =>
Ada.Text_IO.Put_Line("Invalid Option");
end case;
Skip_Line;
exception
when ADA.IO_EXCEPTIONS.Data_Error =>
Ada.Text_IO.Put_Line ("Try a number from 1 to 4, Buddy");
end;
end loop;
end Main;
RESULT:
C:\Users\a0284014\Desktop\ada\exception\obj\main
| CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit
f
Try a number from 1 to 4, Buddy
| CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit
Try a number from 1 to 4, Buddy
| CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit
Try a number from 1 to 4, Buddy
| CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit
Try a number from 1 to 4, Buddy
| CHOOSE YOUR OPTION: 1)Shuffle 2)Pass 3)Enter Word 4)Exit
Try a number from 1 to 4, Buddy
[2015-07-18 20:39:33] process exited with status 1, elapsed time: 10.81s
next prev parent reply other threads:[~2015-07-18 12:41 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-17 15:47 Error "exception not permitted here" when putting EXCEPTION in a loop Trish Cayetano
2015-07-17 15:56 ` David Botton
2015-07-17 15:58 ` G.B.
2015-07-18 8:14 ` Trish Cayetano
2015-07-18 10:08 ` Björn Lundin
2015-07-18 12:41 ` Trish Cayetano [this message]
2015-07-18 13:56 ` Björn Lundin
2015-07-18 14:08 ` Niklas Holsti
2015-07-18 14:56 ` Björn Lundin
2015-07-18 14:32 ` Trish Cayetano
2015-07-18 14:59 ` Björn Lundin
2015-07-18 16:09 ` Dennis Lee Bieber
2015-07-18 18:11 ` Niklas Holsti
2015-07-18 21:16 ` Dennis Lee Bieber
2015-07-17 16:02 ` Björn Lundin
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox