<div dir="ltr"><div>I find the swift grammar at the end of Swift Book very useful. This is the first time I have read a programming language grammar and I really felt why I haven&#39;t done this for my earlier programming languages. For couple of months I have just read the Language guide about using general constructs of swift language, but after reading the grammar and implemented a lexer &amp; scanner(i.e parser, still in development) in swift my understanding of swift syntax is very good.</div><div><br></div><div></div><div>Initially it was difficult to understand some parts of the grammar and its terminology as it was mostly used in compiler development. but apple really made it easy as there are no left recursive terminals.</div><div>Hence forth I decided to first learn the grammar along with its construct guide for any language I am going to learn in the feature.</div><div><br></div><div>The Swift Programming Language book Pages: 848 &amp; 852 explains the if and case-condition clause syntax.</div><div><br></div><div>Note: ‹› stands for optional syntax.</div><div><br></div><div>Excerpt From: Apple Inc. “The Swift Programming Language (Swift 2.1).” iBooks. <a href="https://itun.es/in/jEUH0.l" target="_blank">https://itun.es/in/jEUH0.l</a><br></div><div><br></div><div><b>If syntax:</b></div><div><div>  “if <b>condition-clause</b> code-block ‹else-clause›”</div><div><br></div></div><div><b>case-condition</b>: (is a condition-clause, along with others) <br></div> &quot;case pattern initializer ‹where-clause›&quot;<br><div><br></div><div>Once you understand how to deal with the grammar, then you won&#39;t search for language construct example or tutorials.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 24, 2016 at 11:56 AM, Ramakrishna Mallireddy <span dir="ltr">&lt;<a href="mailto:ramakrishna.malli@gmail.com" target="_blank">ramakrishna.malli@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I am not sure if this helps, This is how I understand it.<div><br></div><div>what happens when you use normal switch.</div><div><br></div><div>switch someEnumExpression {</div><div> case someEnum.Element1: execute block / statements </div><div> default: executeDefault</div><div>}</div><div><br></div><div>// it checks each case with someEnumExpression, and if true then run it, may be actual implementation might use dictionary with someEnum as Key</div><div>if case someEnum.Element1 == someEnumExpression {</div><div>  execute block / statements </div><div>} else {</div><div>  executeDefault</div><div>}</div><div><br></div><div>unroll your switch to if&#39;s, then I am sure you will understand its construct...but why swift provide this control branch statements with case, because at time I am sure that or only want to check an expression is of particular enum case, then I use the if case like above. while is similar.</div><div><br></div><div>I am sorry if my explanation is vague.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Wed, Feb 24, 2016 at 10:49 AM, Thomas# Chiang via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br></span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><div dir="ltr"><div>have any document explain about &quot;while case&quot; and &quot;if case&quot; ? thank you ~<br><br></div>TMS#<br></div>
<br></span>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>