logoISU  

CS256 - Principles of Structured Design

Fall 2021

Displaying ./code/sternflCode/loops

Format:
for(initial; stay-in-condition;  update)
    statement

Example:
for(int x=0; x<10; x++)
{
  printf("%d\n", x);
  x = x+4;
}
---------------------
Format

while(stay-in-condition)
  statement

Example:

int x=0;
while(x<10) {
  printf("%d\n", x);
  x = x+5;
}

-------------------------------
Example:

for(int x=0; x<10; x++) {
  printf("%d\n", x)
  if (x%3==0) continue;  //go back to the update
  printf("Hi, Mom!\n");
}

------------------------

for(int x=0; x<10; x++) {
  printf("%d\n", x)
  if (x%3!=0) 
    printf("Hi, Mom!\n");
}

--------------------------------
int sum=0;
for(int x=0; x<100; x++) {
  sum = sum+x;
  if (sum>1000) {
     printf("sum is %d x is %d\n", sum, x);
     break;
  }
}
printf("Done\n");