1 / 36

Expressions, Conditionals and Looping

Expressions, Conditionals and Looping. CS 3260 Version 1.0. Overview. Flow of Control Statements Expressions & Operators Selection (Conditionals) Iteration (Loop) Method Calls (Invocation). C# Statement Types. All expressions require a boolean exp ression except?. if( exp )

sachi
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 • Flow of Control • Statements • Expressions & Operators • Selection (Conditionals) • Iteration (Loop) • Method Calls (Invocation)

  3. C# Statement Types

  4. All expressions require a booleanexpression except? • if(exp) • if(exp)-else • (exp)?(exp):(exp) • while(exp) • do-while(exp); • switch(exp) • for(<init>; <exp>; <change>) • All of the above. • None of the above.

  5. Statements • Declaration • Variables/Fields/Data • Methods/Functions • Blocks { … } • Expression(s) • Selection (Conditional) • if/if-else/switch/?: • Iteration (Loop) • while/do-while/for/foreach

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

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

  8. Exception Handling, checked/unchecked, unsafe Blocks • try-catch-finally • checked/unchecked • unsafe

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

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

  11. Other Statements • lock • yield • fixed

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

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

  14. Expressions • Primary • void • Arithmetic • Assignment • Logical • Others

  15. Operators • Operators • Unary • Binary • Ternary • Precedence • Associativity

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

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

  18. if / if-else / ?: Selection • if( expr ) <then-statement> • if ( expr ) <then-statement> else <else-statement> • ( expr ) ? ( expr ) : ( expr )

  19. 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>;

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

  21. do loop • do <statement> while ( expr ) ;

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

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

  24. A foreach loop may not work with a? • Single dimensional array • Multiple dimensional array • C# Collections • C# Objects • All of the above. • None of the above.

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

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

More Related