Loops/Continue

Revision as of 15:27, 21 April 2008 by rosettacode>Mwn3d (Created task with C, C++, and Java)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Show the following output using one loop.

Task
Loops/Continue
You are encouraged to solve this task according to the task description, using any language you may know.
1, 2, 3, 4, 5
6, 7, 8, 9, 10

C

Translation of: C++

<c>for(int i = 1;i <= 10; i++){

  printf("%d", i);
  if(i % 5 == 0){
     printf("\n");
     continue;
  }
  printf(", ");

}</c>

C++

Translation of: Java

<cpp>for(int i = 1;i <= 10; i++){

  cout << i;
  if(i % 5 == 0){
     cout << endl;
     continue;
  }
  cout << ", ";

}</cpp>

Java

<java>for(int i = 1;i <= 10; i++){

  System.out.print(i);
  if(i % 5 == 0){
     System.out.println();
     continue;
  }
  System.out.print(", ");

}</java>