1 / 34

Expressions, Conditionals and Looping

Expressions, Conditionals and Looping. CS 3260 Version 1.0. Overview. Statements Expressions Operators Selection (Conditionals) Iteration (Loop). C# Statement Types. Statements. Declaration Variable Method Blocks { … } Expression Selection (Conditional) if/if-else/switch/?:

kinsey
Download Presentation

Expressions, Conditionals and Looping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Expressions, Conditionals and Looping CS 3260 Version 1.0

  2. Overview • Statements • Expressions • Operators • Selection (Conditionals) • Iteration (Loop)

  3. C# Statement Types

  4. Statements • Declaration • Variable • Method • Blocks { … } • Expression • Selection (Conditional) • if/if-else/switch/?: • Iteration (Loop) • while/do-while/for/foreach

  5. Statements • Statement Lists { … } • ; - Empty • <label>: <statement>; • Declaration - <type> <ident> = <init>; • Expression • Selection (Conditional) • Iteration (Loop)

  6. Jump Statements • goto <label> - jump to label • break – switch/loops • continue - loops • return – no-value/value • throw – Exception object • yield – continue/break

  7. Exception Handling Statementschecked/unchecked Block • try-catch-finally • checked/unchecked

  8. try-catch-finally • try: try-blockcatch(...) { //catch-block-1 }...catch(...) { //catch-block-n } • try: try-block finally: finally-block

  9. using Statements • using <namespace> • using ( resource-acquisition ) embedded-statement

  10. Other Statements • lock • yield • fixed

  11. lock Statement • lock ( expr ) embedded-statement

  12. yield Statement • yield return expr ; • yield break;

  13. Expressions • Primary • void • Arithmetic • Assignment

  14. Operators • Operators • Precedence • Associativy

  15. Suffixes real-type-suffix: one ofF f D d M m

  16. Selection - Conditional • if (<boolean expression>) <statement>; • if(<boolean expression>) <statement> else <statement>; • switch(<integer expression) { <statements> } • <datatype> <ident> = (<expression)?<true_value>:<false_value>

  17. if - Selection • if ( expr ) then-stmt else else-stmt

  18. Iteration - Loop • while(<bool expression>) <statement>; • do <statement> while(<bool expression); • for(<init statement>; <boolexpr>; <change statement>;) <statement>; • foreach(<type> <ident> <type> in <ident>) <statement>;

  19. while - Loop • while-statement:while(boolean-expression ) embedded-statement

  20. do loop • do-body while ( expr ) ;

  21. for - Loop • for ( for-initializer ; for-condition ; for-iterator ) embedded-statement

  22. foreach Loop • foreach(<datatype> <ident> in <enumerable_collection>) • <statement(s)>

  23. throw - return • throw expr ; • return expr ; or return ;

  24. Executable Statements • Methods • Properties • Events • Indexers • User-defined operators • Instance constructors • Static constructors • Destructors

More Related