3.0 For loop #

Created Tuesday 22 October 2019 structure of a for loop: init variable(s) while(check_condition){




incerement/decrement; }

structure for the for loop: for(init; condition_check; increment){




} for and while are exactly the same, except jargon. Advantages of a for loop:

  1. We tend to forget the increment condition, this helps in avoiding the mistake.
  2. It makes the code neater.

Important:

  1. All the three parts of the for are optional, we can skip one or more of them. But the three semicolons are **compulsory. **http://www.cplusplus.com/doc/tutorial/control/
  2. In the initialization, we can initialize multiple variables, separated by commas. It’s(first expression’s) value does not matter anyway.
  3. In the check_condition, all boolean expressions have to be connected using bool operators only, no commas should be used.
  4. the increment part can have multiple increment parts separated by commas.

Running time:

State: The start state is the initializer. The end state is the checker or a break inside the body.

**A hard lesson: The order of content in a loop does matter. **