Loops/Nested: Difference between revisions

Content added Content deleted
(Added C implementation without goto)
Line 663: Line 663:
return 0;
return 0;
}</lang>
}</lang>

Using break, the preferred alternative to goto
<lang C>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
int main() {
int a[10][10], i, j;
srand(time(NULL));
for (i = 0; i < 10; i++)
for (j = 0; j < 10; j++)
a[i][j] = rand() % 20 + 1;
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
printf(" %d", a[i][j]);
if (a[i][j] == 20)
break;
}
if (a[i][j] == 20)
break;
printf("\n");
}
printf("\n");
return 0;
}
</lang>


=={{header|C sharp|C#}}==
=={{header|C sharp|C#}}==