Loops/Continue: Difference between revisions
< Loops
Content added Content deleted
(Created task with C, C++, and Java) |
m (Of course I forgot the iteration category link) |
||
Line 1: | Line 1: | ||
{{task}}Show the following output using one loop. |
[[Category:Iteration]]{{task}}Show the following output using one loop. |
||
1, 2, 3, 4, 5 |
1, 2, 3, 4, 5 |
||
6, 7, 8, 9, 10 |
6, 7, 8, 9, 10 |
Revision as of 15:28, 21 April 2008
Loops/Continue
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Show the following output using one loop.
1, 2, 3, 4, 5 6, 7, 8, 9, 10
C
<c>for(int i = 1;i <= 10; i++){
printf("%d", i); if(i % 5 == 0){ printf("\n"); continue; } printf(", ");
}</c>
C++
<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>