Count Up and Down in the Same Loop
I have run in to a few situations lately where I thought it would be nice to iterate up and down within the same loop. Here is a basic example that just prints the counting values of the for loop to the console.
I have run in to a few situations lately where I thought it would be nice to iterate up and down within the same loop. Here is a basic example that just prints the counting values of the for loop to the console.
void updown(int count){
for (int i=0, j=count; i<=count && j>=0; i++, j--) {
printf("i = %d\tj = %d\n", i, j);
}
}