HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

One line ifs and fors

05-10-2007, 04:08 PM#1
Vexorian
I've been thinking on how annoying:

Collapse JASS:
if (i==4) then
    return true
endif

Is , seriously. I 've been thinking that if we had a rule in which if set,call or return are found after then we can allow it to take one line:

Collapse JASS:
  if (i==4) then return true

Also we could use for loops

Collapse JASS:
     for i=4 to 34 do set k[i]=i*2

for could become multi line like

Collapse JASS:
     for i=4 to 34 do
         set k[i]=i*2
         set k[i]=k[i]-k[i-1]
     endloop


opinions?
05-10-2007, 04:24 PM#2
Toink
I like the one line if-then , but the second one confuses me. for i==4 to 34 what does that mean?
05-10-2007, 04:26 PM#3
Rising_Dusk
Looks kinda like...
Collapse JASS:
local integer i = 4
loop
    exitwhen i >= 34
    set i = i + 1
endloop
05-10-2007, 04:27 PM#4
Toink
Ohh I likey! Add it to NewGen please :) It(one line ifs) would certainly reduce some lines of code.
05-10-2007, 04:28 PM#5
Toadcop
opinions - only usable for who like it... i don't like it =)
05-10-2007, 04:29 PM#6
Toink
Then don't use it :)
05-10-2007, 04:29 PM#7
Vexorian
Well you can commit suicide if you don't like it, or you may just don't use it, you decide.

Dusk: for would actually be like

Collapse JASS:
local integer i = 4
loop
    exitwhen i > 34
    set i = i + 1
endloop

And damn Toink, I was typing this post before yours appeared.
05-10-2007, 04:33 PM#8
Strategy Master
Oh please so add this vex. I've always worshiped the chance to do this. Its damn annoying when you forget this is jass and you can't do something as simple as this.
05-10-2007, 04:33 PM#9
Toink
I rly like both ideas. <3

EDIT: Uh oh another jynx! This time with Strategy_Master! It Might be a coincidence or I might be psychic :P
05-10-2007, 04:58 PM#10
Earth-Fury
I like both ideas too, vex :D
05-10-2007, 05:11 PM#11
Euroset
vex, good post! Really loop/endloop usable only for not integer variables. For example, you want to stop loop if any condition, or function returns true.
But for all integer simple-step loops your code is likely!
05-10-2007, 06:17 PM#12
Alevice
Your first example it s apretty bad example of "if one liners" (great made up term), for it would be done like return (i==4).

They still would rule for those cases that make more sense.
05-10-2007, 06:24 PM#13
Earth-Fury
Quote:
Originally Posted by Alevice
Your first example it s apretty bad example of "if one liners" (great made up term), for it would be done like return (i==4).

They still would rule for those cases that make more sense.
Except it wouldn't be, because if its false it would not return at all in vex's example. (not trying to be rude or anything, just pointing it out)
05-10-2007, 07:02 PM#14
Anitarf
ahh, for... Reminds me of Basic. :)
05-10-2007, 07:48 PM#15
Tiki
$vexorian = ($god) ? true : false;