Tuesday, March 15, 2011

3.5 Loops - While and For

  • While syntax:




  • Expression is evaluated. If expression is true, statement is executed and expression is re-evaluated. Cycle continue until expression is zero
  • for syntax:





  • Commonly, expr1 and expr3 are assignments or function calls and expr2 is a relational expression
  • for is preferable when there is a simple initialization and increment
  • Comma " , " operator is used to place multiple expressions in a for statement:




No comments:

Post a Comment