Guest User

Untitled

a guest
Jan 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. AN ES6 ELSE-BLOCK PROPOSAL
  2. ============================
  3.  
  4. ## Syntax
  5.  
  6. Else-Statement :=
  7. { Statement } else Statement
  8. { Statement } else { Statement }
  9.  
  10. Each else for which the choice of associated if is ambiguous shall be associated with the nearest possible if that would otherwise have no corresponding else.
  11.  
  12.  
  13. ## Semantics
  14.  
  15. The production { Statement } else { Statement } is evaluated as follows:
  16.  
  17. 1. let rA be a boolean. If the first Statement was executed set rA to true. Otherwise( if the execution was blocked by an if statement) let rA be false.
  18. 2. if rA is true, then
  19. a. skip the second Statement and continue afterwards.
  20. 3. else,
  21. b. execute the second Statement.
  22.  
  23.  
  24. ## Notes
  25.  
  26. I hope TC39 agrees that this is a valuable extension to boolean logic. This allows for much easier readable code like:
  27.  
  28. if ( mustgotowork() ) { wakeup(); } else { sleepsomemore(); } else { brush_teeth(); } else { sleepsomemore(); } else { putclotheson() } else { wakeup(); } else { drivetowork(); } else { invitesomechicks() }
  29.  
  30. Also, block parens are not optional for better visual highlighting.
Add Comment
Please, Sign In to add comment