#include #include int main() { int a[] = {5, 4, 3, 2, 1}; int size = 5; int i; // All the loops below provide equivalent behavior // Remember with for loop: // First statement executed // Conditional Checked // if "True" do loop // otherwise exit // after each execution of loop run third statement printf("Loop with i++ statement:\n"); for (i = 0; i < size; i++) { printf("\ta[%d] = %d\n", i, a[i]); } printf("\ti = %d\n", i); // Equivalent While loop printf("Do while loop with i++ statement:\n"); i = 0; while (i < size) { printf("\ta[%d] = %d\n", i, a[i]); i++; } printf("\ti = %d\n", i); //----------------------------------------------------------------- printf("Loop with ++i statement:\n"); for (i = 0; i < size; ++i) { printf("\ta[%d] = %d\n", i, a[i]); } printf("\ti = %d\n", i); printf("Do while loop with ++i statement:\n"); i = 0; while (i < size) { printf("\ta[%d] = %d\n", i, a[i]); ++i; } printf("\ti = %d\n", i); //----------------------------------------------------------------- printf("Loop with ++i conditional:\n"); for (i = -1; ++i < size;) { printf("\ta[%d] = %d\n", i, a[i]); } printf("\ti = %d\n", i); printf("Do while loop with ++i conditional:\n"); i = -1; while (++i < size) { printf("\ta[%d] = %d\n", i, a[i]); } printf("\ti = %d\n", i); //----------------------------------------------------------------- printf("Loop with i++ conditional:\n"); for (i = -1; i++ < size - 1;) { printf("\ta[%d] = %d\n", i, a[i]); } printf("\ti = %d\n", i); printf("Do while loop with i++ conditional:\n"); i = -1; while (i++ < size - 1) { printf("\ta[%d] = %d\n", i, a[i]); } printf("\ti = %d\n", i); return 0; }