Hi, I'm learning C and have been stumbling my way about. Anyhow, I've been wondering if it is poor practice to control a while loop with a flag. I've found it convenient at times. I assume it is probably better to use the condition that causes the flag to change but sometimes I have more than one thing that should cause me to get out of the loop. Also, setting the flags value based on the condition that caused the flag to be set seems like it can come in handy after the loop. Here's a code snippet of an example (sorry if it's not the greatest..)
Code:
while(!flag)
{
smaller=i;
if(left <= n && array[left] < array[i])
smaller=left;
if(right <= n && array[right] < array[smaller])
smaller=right;
if(smaller != i)
{
tmp=array[i];
array[i]=array[smaller];
array[smaller]=tmp;
i=smaller;
left=2*i;
right=2*i+1;
}
else
flag=1;
if(left > n)
flag=2;
}
Is that ok? I'm trying to avoid developing bad habits and often the feedback I get from instructors is a bit lacking. Thanks!