<div dir="ltr"><font face="monospace, monospace">I find myself writing the same else blocks for guard statements over and over again, so it might be reasonable to think about a default behaviour.<br><br>In a current project I found 217 guard statements from which 183 have repetitive else clauses<br><br>From which:<br>131 end with &quot;else { return nil }&quot;<br>44 &quot;else { return }&quot;<br>6 &quot;else { continue }&quot;<br>2 &quot;else { break }&quot;<br><br>My proposal would be to make the else block optional and define a default behaviour.<br><br>For example:<br><br>func foo(x: Int) {<br><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    ​</div>guard x &lt; 10<br><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    ​</div>...<br>}<br><br>swift would implicitly add &quot;else { return }&quot;<br><br>--<br><br>func foo(x: Int) -&gt; Int? {<br><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    ​</div>guard x &lt; 10<br><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    ​</div>...<br>}<br><br>swift would implicitly add &quot;else { return nil }&quot;<br><br>--<br><br>for i in 0..&lt;10 {<br><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    ​</div>guard i%2 == 0<br>}<br><br>swift would implicitly add &quot;else { continue }&quot;<br><br>--<br><br>switch {<br>case a :<br><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    ​</div>guard x != y<br>case b :</font><div><font face="monospace, monospace"><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    ...​</div><br>}<br><br>swift would implicitly add &quot;else { break }&quot;<br><br>--<br><br>func foo(x: Int) -&gt; Int {<br><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    ​</div>guard x &lt; 10<br><div class="gmail_default" style="font-family:monospace,monospace;display:inline">​    ​</div>...<br>}<br><br>swift would provide a warning that the guard statement needs an else block<br><br>--<br><br>Possible advantages<br>- Less code<div class="gmail_default" style="font-family:monospace,monospace;display:inline">​ to write​</div><br>- visually cleaner<br>-<div class="gmail_default" style="font-family:monospace,monospace;display:inline">​ ​</div>In code with multiple guard statements<div class="gmail_default" style="display:inline">​ ​</div>you<div class="gmail_default" style="display:inline">​ ​</div>would not have to repeat the else block<br><br><br>Possible Disadvantages<br>- Different behaviour in different contexts (func/return, for/continue, switch/break, …) needs to be learned and understood<br>- programmers might forget that guard + else {} is an option</font><br></div></div>