Following is the insertion sort code i wrote
#include<stdio.h>
#include<conio.h>
void main()
{
int i, j, a[10], temp, f = 0, k = 0;
clrscr();
printf("\n\t\t\t\tINSERTION SORT\nEnter the Array:-\n");
for (i = 0; i <= 9; i++)
scanf("%d", &a[i]);
for (i = 0; i <= 9; i++) // 1st for loop
{
temp = a[i];
for (j = 0; j <= i - 1; j++) // 2nd for loop
{
f = 0;
if (a[i]<a[j]) // if loop
{
for (k = i - 1; k >= j; k--) // 3rd for loop
a[k + 1] = a[k];
a[k + 1] = temp;
break; // break statement
}
}
}
printf("\nThe sorted array is:-\n");
for (i = 0; i <= 9; i++)
printf("%d\n", a[i]);
getch();
}
I was told that break statement stops that particular instant(nth time of currently running innermost loop & initiates its next instance ( n+1 time). So here I am confused that whether the break statement here will stop the 3rd loop or if condition. I was however told that it will affect the second loop.
Can anyone here please tell me on which for loop it is going to have its effect.