I have this function I'm making to count voter preferences in C. It's set so that if it finds a candidate that has not been eliminated and matches the current preference we're checking to then add a vote. I then finish it to set
preference = candidate_count +1;
and terminate the while loop, but could I use return here? Could I use return to exit the nested for loop and the while loop to go back to the main for loop?
In a situation where the candidate is eliminated I do
else preference++; j = 0;
If I did return here would it go back to the nested for loop. I'm just a little confused because it seems you can write code without ever using return if you set some base to terminate the program.
for(int i =0; i<voter_count;i++)
{
//restart the for loop and look for preference 1
int preference =0;
while (preference <candidate_count)
{
for(int j = 0; j<candidate_count;j++)
{
if(preferences[i][j] == preference)
{
if(candidates[j].eliminated == false)
{
candidates[j].votes ++;
preference = candidate_count +1;
}
else
preference++;
j = 0;
}
}
}
}