comp.lang.ada
 help / color / mirror / Atom feed
* string comparison?
@ 1997-10-16  0:00 Tri Tram
  1997-10-17  0:00 ` Tom Moran
  1997-10-17  0:00 ` Steve Doiel
  0 siblings, 2 replies; 3+ messages in thread
From: Tri Tram @ 1997-10-16  0:00 UTC (permalink / raw)




	I am new to the ada programming language and I would appreciate it
if somebody could help me out with a couple of things.
1.  Is there anyway to do a string comparison in ada?
    So far, I have done it character by character but I am wondering if there
    is a better way to do it?  
2.  Is there anyway to exit out of a program inside an if-then-else statement?
    I have a program that waits for a command, and depending on that command,
    it would do something.  So I thought that the quit command would be 
    simplest.  But I can't even exit out of the if-then-else block.  

TIA.

-----------------------------------------------------------------
Tri Tram, Computer Science and Engineering at UCLA
http://www.seas.ucla.edu/~tram




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: string comparison?
  1997-10-16  0:00 string comparison? Tri Tram
  1997-10-17  0:00 ` Tom Moran
@ 1997-10-17  0:00 ` Steve Doiel
  1 sibling, 0 replies; 3+ messages in thread
From: Steve Doiel @ 1997-10-17  0:00 UTC (permalink / raw)



In article <EI5vIH.Et7@seas.ucla.edu>, tram@mulholland.seas.ucla.edu says...
>
>
>        I am new to the ada programming language and I would appreciate it
>if somebody could help me out with a couple of things.
>1.  Is there anyway to do a string comparison in ada?
>    So far, I have done it character by character but I am wondering if there
>    is a better way to do it? 

Sure, how about:

DECLARE
  ucToken : String := "CONST";
BEGIN
  IF ucToken = "CONST" THEN
    DoSomething;
  END IF;
END;

>2.  Is there anyway to exit out of a program inside an if-then-else 
statement?
>    I have a program that waits for a command, and depending on that command,
>    it would do something.  So I thought that the quit command would be 
>    simplest.  But I can't even exit out of the if-then-else block.

IF Ada.Characters.Handling.To_Upper( response ) = "QUIT" THEN
  RETURN;
END IF;

-- Since the main program in Ada is a procedure, you can RETURN to leave
-- the main procedure.

>
>TIA.
>
>-----------------------------------------------------------------
>Tri Tram, Computer Science and Engineering at UCLA
>http://www.seas.ucla.edu/~tram





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: string comparison?
  1997-10-16  0:00 string comparison? Tri Tram
@ 1997-10-17  0:00 ` Tom Moran
  1997-10-17  0:00 ` Steve Doiel
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Moran @ 1997-10-17  0:00 UTC (permalink / raw)



>1.  Is there anyway to do a string comparison in ada?
>    So far, I have done it character by character but I am wondering if there
>    is a better way to do it?  
   subtype Punched_Cards is string(1 ..  80);
   a, b : Punched_Cards;
  ...
  if a = b then ...
 if a < b then ...

>2.  Is there anyway to exit out of a program inside an if-then-else statement?
>    I have a program that waits for a command, and depending on that command,
>    it would do something.  So I thought that the quit command would be 
>    simplest.  But I can't even exit out of the if-then-else block.
  If you want to exit a subroutine, you can do a 'return'.  If you
want to exit from a loop, use 'exit'.  I don't understand what you
might mean by being stuck inside an 'if' block.  Are you trying to
abort the whole program from deep inside some set of subroutines?
Perhaps you want to raise an exception, eg. "raise
Abandon_Ship_Every_Man_For_Himself".  Or do you want to go so far as
to reboot the computer, in which case you will need some OS call
specific to your target environment.   Or if this is an embedded
system and you want to trigger a booby-trap explosive device, the
method will depend on the target hardware.  




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-10-17  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-16  0:00 string comparison? Tri Tram
1997-10-17  0:00 ` Tom Moran
1997-10-17  0:00 ` Steve Doiel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox