[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

If-Then and "End"

Sam C.

1/23/2007 4:32:00 AM

I am making a program with various commands. One of them is "Exit" which
is supposed to exit the program. Here is my code:

if uinput = "EXIT" then
end
end

The problem is that the ruby compiler thinks that the first "end" is the
end to the If-Then statement, instead of the "end" that ends the
program. How do I work around this?

--
Posted via http://www.ruby-....

8 Answers

Chris Shea

1/23/2007 4:39:00 AM

0

Sam C. wrote:
> I am making a program with various commands. One of them is "Exit" which
> is supposed to exit the program. Here is my code:
>
> if uinput = "EXIT" then
> end
> end
>
> The problem is that the ruby compiler thinks that the first "end" is the
> end to the If-Then statement, instead of the "end" that ends the
> program. How do I work around this?
>
> --
> Posted via http://www.ruby-....

if uinput = "EXIT" then
exit
end

That should work. Each 'end' is matched with the closest previous
unmatched block opener ('if' in this case). It doesn't have anything to
do with terminating a script. hth

Gary Wright

1/23/2007 4:45:00 AM

0


On Jan 22, 2007, at 11:32 PM, Sam C. wrote:

> I am making a program with various commands. One of them is "Exit"
> which
> is supposed to exit the program. Here is my code:
>
> if uinput = "EXIT" then
> end
> end
>
> The problem is that the ruby compiler thinks that the first "end"
> is the
> end to the If-Then statement, instead of the "end" that ends the
> program. How do I work around this?

I think you are looking for 'exit' as the method to call to terminate
a program.
Also you aren't doing a comparison in your if condition, you are
doing an assignment.
So you want something like:

if uinput == "EXIT" then
exit
else
# do something else
end


Gary Wright




Wang Dong

1/23/2007 4:54:00 AM

0


"Sam C." <mathwhiz728@gmail.com> дÈëÏûÏ¢ÐÂÎÅ:dde09efd974a47ac491498b540e43ed1@ruby-forum.com...
>I am making a program with various commands. One of them is "Exit" which
> is supposed to exit the program. Here is my code:
>
> if uinput = "EXIT" then
> end
> end
>
> The problem is that the ruby compiler thinks that the first "end" is the
> end to the If-Then statement, instead of the "end" that ends the
> program. How do I work around this?
>
> --
> Posted via http://www.ruby-....
>

It's not the Pascal£¬program end with an 'End.', just use exit.


Robert Klemme

1/23/2007 7:59:00 AM

0

On 23.01.2007 05:45, gwtmp01@mac.com wrote:
>
> On Jan 22, 2007, at 11:32 PM, Sam C. wrote:
>
>> I am making a program with various commands. One of them is "Exit" which
>> is supposed to exit the program. Here is my code:
>>
>> if uinput = "EXIT" then
>> end
>> end
>>
>> The problem is that the ruby compiler thinks that the first "end" is the
>> end to the If-Then statement, instead of the "end" that ends the
>> program. How do I work around this?
>
> I think you are looking for 'exit' as the method to call to terminate a
> program.
> Also you aren't doing a comparison in your if condition, you are doing
> an assignment.
> So you want something like:
>
> if uinput == "EXIT" then
> exit
> else
> # do something else
> end

Alternatively

exit if uinput == "EXIT"
....

robert

Ben Giddings

1/23/2007 9:16:00 PM

0

On Jan 23, 2007, at 04:47, Lloyd Zusman wrote:
> Just a small point: you don't need an 'else' clause after an 'exit',
> since nothing could follow that statement. Hence, you can just do
> this
> if you want, and it will have the same effect:
>
> if uinput == "EXIT" then
> exit
> end
> # do something else
>
> I tend to do that with 'exit', 'return', 'raise', 'throw', 'next',
> 'redo', and 'break' statements, to avoid excessive nesting. But
> that's
> just a stylistic thing.

For that matter, you don't need "then" unless it's all on one line:

if uinput == "EXIT" then exit end

exit if uinput == "EXIT"

or

if uinput == "EXIT"
exit
end

For safety reasons, you could even do:

if "EXIT" == uinput
exit
end

this way if you accidentally use "=" instead of "==" you'll get an
error:

Ruby will give you a warning if it spots a "=" in a conditional, but
often you want an error instead.

Ben


deep

7/8/2013 3:24:00 PM

0

On Mon, 08 Jul 2013 09:30:03 -0500, John <johnwayne@oldwest.net>
wrote:

>deep wrote:
>> Holy shit poor George looks terrified. Wiping sweat from the back of
>> his neck. Announcer said defense was considering putting him on the
>> stand. They might as well just put the noose around his neck. Poor
>> George. All those years he just figured he could kill some black guy
>> and just get away with it. Boy is he surprised. The defense's best
>> bet now is to just plead temporary insansity and throw themselves on
>> the mercy of the court. The guy might get a few years in Florida's
>> mental health system, which I'm sure isn't very good but it's better
>> than what the killer deserves.
>
>We should feel sorry for you, but we don't.

Don't feel sorry for me. Feel sorry for your boy George. He's so
fucked... either way. Even if he gets acquitted. He's still fucked.

JohnJohnsn

7/8/2013 3:46:00 PM

0


In article <tamlt8p4lg3rrb4fn2ref1lgeri5h9dgt8@4ax.com>, Tiefe Schei?e
<dudu@propagandists.brady.org> says...
>
> On Mon, 08 Jul 2013 09:30:03 -0500, John <johnwayne@oldwest.net>
> wrote:
>
>>deep wrote:
>>> Holy shit poor George looks terrified. Wiping sweat from the back of
>>> his neck. Announcer said defense was considering putting him on the
>>> stand. They might as well just put the noose around his neck. Poor
>>> George. All those years he just figured he could kill some black guy
>>> and just get away with it. Boy is he surprised. The defense's best
>>> bet now is to just plead temporary insansity and throw themselves
>>> on the mercy of the court. The guy might get a few years in Florida's
>>> mental health system, which I'm sure isn't very good but it's better
>>> than what the killer deserves.
>>
>> We should feel sorry for you, but we don't.
>
> Don't feel sorry for me. Feel sorry for your boy George. He's so
> fucked... either way. Even if he gets acquitted. He's still fucked.
>
In Zimmerman trial, prosecution's case circling the drain
By The Washington Times
George Zimmerman's defense attorneys have yet to take the field, but they're
already up by double digits.
http://www.washingtontimes.com/news/2013/jul/2/prosecution-faces-st...
zimmerman-case/

"I would wile away the hours, talkin' with the flowers,
if I only had a braaaaaaaaain"
--Schei?ekopf Tiefe Schei?e, Apr 20, 2013

GaryWillis

7/8/2013 3:53:00 PM

0



"deep" wrote in message news:tamlt8p4lg3rrb4fn2ref1lgeri5h9dgt8@4ax.com...

On Mon, 08 Jul 2013 09:30:03 -0500, John <johnwayne@oldwest.net>
wrote:

>deep wrote:
>> Holy shit poor George looks terrified. Wiping sweat from the back of
>> his neck. Announcer said defense was considering putting him on the
>> stand. They might as well just put the noose around his neck. Poor
>> George. All those years he just figured he could kill some black guy
>> and just get away with it. Boy is he surprised. The defense's best
>> bet now is to just plead temporary insansity and throw themselves on
>> the mercy of the court. The guy might get a few years in Florida's
>> mental health system, which I'm sure isn't very good but it's better
>> than what the killer deserves.
>
>We should feel sorry for you, but we don't.

Don't feel sorry for me. Feel sorry for your boy George. He's so
fucked... either way. Even if he gets acquitted. He's still fucked.

#####
You have it all wrong butterball.
He's "Nobody's Boy" but yours.
All YOU want is a "mix breed" declared guilty, because he used a gun.
That's it, nothing more.