Statements

T

TheTacoBellD

Guest
<span class="hi">...</span>
<span class="keyword"> endif</span>
</pre>

<p>An if-then-else statement is a conditional branch that spans multiple lines.
In each condition block (begun with an <code>if</code> and ended with a
<code>endif</code>), each predicate expression is evaluated in turn (first the
one in the <code>if</code>, then the one in the next <code>elseif</code>,
etc.). Each must return a boolean value. The first predicate which evaluates
to true causes its associated statements to be executed (the statements in
the immediately proceeding sub-block). The remainder of the statements in
the other sub-blocks are ignored.

<p>If none of the predicates return true, then the <code>else</code> statements
are executed. There may be zero or more <code>elseif</code>s and the
<code>else</code> is optional (if it is ommitted, then nothing is executed
if no predicates are satisfied). For example:

<pre class="source">
<span class="comment">// (1)</span>
<span class="keyword"> if</span> <span class="hi">predicate</span> <span class="keyword">then</span>
<span class="hi">...</span>
<span class="keyword"> elseif</span> <span class="hi">predicate</span> <span class="keyword">then</span>
<span class="hi">...</span>
<span class="keyword"> endif</span>

<span class="comment">// (2)</span>
<span class="keyword"> if</span> <span class="hi">predicate</span> <span class="keyword">then</span>
<span class="hi">...</span>
<span class="keyword"> else</span>
<span class="hi">...</span>
<span class="keyword"> endif</span>

<span class="comment">// (3)</span>
<span class="keyword"> if</span> <span class="hi">predicate</span> <span class="keyword">then</span>
<span class="hi">...</span>
<span class="keyword"> endif</span>
</pre>

<p><strong>Loop</strong>

<pre class="source">
<span class="keyword"> loop</span>
<span class="hi">statement</span>
<span class="hi">statement</span>
<span class="hi">...</span>
<span class="keyword"> endloop</span>
</pre>

<p>A <code>loop</code> statement contains a block of statements that are
executed continuously. When execution reaches the end of the loop block,
we return to the top of the loop and begin again.

<p>To exit a loop block, one of the enclosed statements must be an
<code>exitwhen</code> statement. It is legal to have an infinite loop
(one that never exits; for example, a main-execution loop in an AI).

<p><strong>Exitwhen</strong>

<pre class="source">
<span class="keyword"> loop</span>
<span class="hi">...</span>
<span class="keyword"> exitwhen</span> <span class="hi">expression</span>
<span class="hi">...</span>
<span class="keyword"> endloop</span>
</pre>

<p>The <code>exitwhen</code> statement is used within a loop. The expression
must evaluate to a boolean value. If it evaluates to true, then execution
immediately exits the inner-most loop that the <code>exitwhen</code> is in.
The <code>exitwhen</code> may be within an if-then-else block inside the
loop and there may be multiple <code>exitwhen</code>s within a single loop;
for example:

<pre class="source">
<span class="keyword"> local</span> <span class="type">integer</span> iterations = 10
<span class="keyword"> loop</span>
<span class="keyword"> if</span> DidTheThingEnoughTimes() <span class="keyword">then</span>
<span class="keyword"> call</span> DisplayText(<span class="str">"Exiting Early"</span>)
<span class="keyword"> exitwhen</span> true
<span class="keyword"> endif</span>
<span class="keyword"> call</span> DoSomething()
<span class="keyword"> set</span> iterations = iterations - 1
<span class="keyword"> exitwhen</span> iterations == 0
<span class="keyword"> endloop</span>
</pre>

<p><strong>Return</strong>

<pre class="source">
<span class="keyword"> return</span> <span class="comment">// (1)</span>

<span class="keyword"> return</span> <span class="hi">expression</span> <span class="comment">// (2)</span>
</pre>

<p>The <code>return</code> statement causes execution to exit from the function
and return to the point after it was called. If the function is declared to
return a value, then the return statement must be used with an expression,
which is the value that is returned to the caller. The expression must evaluate
to a value that conforms to the function's declared type. There may be
multiple <code>return</code>s within a function. All execution paths within
a function must lead to a valid return (unless the function returns
<code>nothing</code>, in which case there is an implicit return when execution
reaches the end of the function).

<p><em>Important Note</em>: currently, the return value only needs to conform
to the native base type of the declared return type, not the declared return
type itself (E.G., if the declared type is <code>unit</code>, the value only
needs to conform to <code>handle</code>). This is a <strong>bug</strong> in
Blizzard's type checker. However, because this bug shows up in Blizzard's own
JASS code, the current version of the syntax checker purposely contains
this behavior also. You should avoid exploiting this because there is
almost no scenario where it is correct.

<p><strong>Debug</strong>

<pre class="source">
<span class="keyword"> debug</span> <span class="hi">statement</span>
</pre>

<p>Any <code>set</code>, <code>call</code>,
<code>if then else</code>, and <code>loop</code>
statement can be prefixed with <code>debug</code>. This
implies the statement is only executed if an game-internal debug flag is
enabled. You probably can't turn it on unless you work for Blizzard.



</body>
</html>


I might have possibly understood this passage from the JASS Manuel entitled "Statements", but the code makes it a lot more confusing believe it or not. So could anyone kind of sum up what "Statements" are?

I don't mean sum up this entire passage, I just want you to tell me a bit about them if possible. If I understand the subject some more I might understand this more clearly.

P.S. If there is something I should understand before learning about statements, please tell me.
 

SFilip

Gone but not forgotten
Reaction score
634
statements are similar to functions, but they work differently.
there are 2 types of statements in jass: if..then and loop.
i believe that if you understand these in gui (if conditions then actions and for each integer variable) you should have no trouble understanding them in jass.
if..then is defined like this
Code:
if <condition, should be boolean/boolexpr) then
    <actions>
else [COLOR=Red]//optional[/COLOR]
    <else actions>
endif
loops are created this way
Code:
loop
    <actions>
endloop
<actions> must contain exitwhen or else the loop will simply become infinite and crash.
exitwhen also needs a condition. best way to show this is a complete example...
Code:
local i = 0 [COLOR=Red]// first we need a variable to use[/COLOR]
loop
    exitwhen i == 10 [COLOR=Red]// every time the loop runs it will check if i is 10 and will break if it is[/COLOR]
    call BJDebugMsg(I2S(i)) [COLOR=Red]// simply show a text message that displays the current "position" of i[/COLOR]
    set i = i + 1 [COLOR=Red]// increase i by 1...or else you have an infine loop
endloop[/COLOR]
of course all of these lines can suit your needs. you can increase i by 2 or whatever you want. exitwhen can take any condition. for example you can make an action that kills all units and stops when the caster dies (exitwhen IsUnitDeadBJ(castervariable) == true). this is also another nice advantage of jass over gui ;)
 
T

TheTacoBellD

Guest
Cool. I'm pretty sure I get it. But should I first learn functions and THEN statements?
 

SFilip

Gone but not forgotten
Reaction score
634
not important...well you learned statements now, didn't you? there isn't really much more that i know of than the things mentioned in my post.
 
T

TheTacoBellD

Guest
SFilip said:
not important...well you learned statements now, didn't you? there isn't really much more that i know of than the things mentioned in my post.


Oh. Well that's good.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top