1
edit
Changes
m
→Discussion: Use of iterating variables on for loops
int *p1;
char *p2;
=== (Discussion: Use of iterating variables on for loops) ===
There are two major ways of dealing with the iteration variable on '''for''' loops. We should come to a consensus on how to deal with it on our project.
Option 1: Declare the variables outside the loop; initialize them inside the loop; keep their exit values for future use.
int i;
for (i = 0; i<5; i++) printf("."); // Prints .....
printf("%d",i); // Prints 5
Option 2: Declare and initialize variables inside the loop; lose the variable at the end of the loop scope;
for (int i = 0; i<5; i++) printf("."); // Once the loop is done, variable i cannot be accessed anymore.
{| class="wikitable" border="1"
|+ Discussion
! Name !! Comment
|-
| fmDeOliveira || I definitely prefer option 2. It is much easier to keep recycling the loop variables without having to worry if they already exist or not. In case we need the value of the loop variable after the loop is done, we should just copy it to another variable before the end of the loop.
|-
|}