the explaination of the keyword "then"?

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
I guys I was wounder I saw a keyword named "then" in ruby but I was curious of his use....so if someone can explain me what is this use I would apreciate :)

thanks~

all regards 

Nio Kasgami
 
Last edited by a moderator:

kerbonklin

Hiatus King
Veteran
Joined
Jan 6, 2013
Messages
1,726
Reaction score
275
First Language
English
Primarily Uses
RMMV
Note that using "then" only works if the case only has one following statement. You cannot say for example

if x == 20 then y = 30

z = 30
Otherwise the Z will not be part of the case statement, If you wanted to include the Z in the case, it has to be:

if x == 20

  y = 20

  z = 30

end
Also note that you do not use "end" with "then".
 
Last edited by a moderator:

cremnophobia

Veteran
Veteran
Joined
Dec 10, 2013
Messages
216
Reaction score
97
Primarily Uses
The keyword then can be used with if, unless, case/when and rescue expressions, but it's optional. As Hudell already has mentioned, it's useful to put code into the same line. then is one way to achieve that, since otherwise Ruby doesn't know which piece of code is the controlling expression / conditional and which piece is the code that gets executed (the then-clause). Usually a line terminator is used, but then they can't be on the same line! The other way is a bit uglier: a semicolon. There was another way in old Ruby versions (a colon), however it has been removed.

It's rarely used except with (simple) case-expressions:

Code:
current_rpgmaker =  case year  when 1997..1999 then '95'  when 2000..2001 then '2000'  when 2002..2003 then '2003'  when 2004..2006 then 'XP'  when 2007..2010 then 'VX'  when 2011..2015 then 'VX Ace'  else 'unknown'  end
 
Last edited by a moderator:

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
wow then this a really cool explaination thanks guys : D 

but yeah for me then = "donc" in english so this was more

if my variable equal 10 then my other variable equal 10
 

Lemur

Crazed Ruby Hacker
Veteran
Joined
Dec 1, 2014
Messages
106
Reaction score
124
First Language
English
Primarily Uses
Most of the time you should just use suffix expressions:

Code:
foo = bar if baz
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
Most of the time you should just use suffix expressions:

foo = bar if baz
well this was more for know is use sincerelly haha because I am always curious on that!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,018
Members
137,563
Latest member
MinyakaAeon
Top