I am writing a script to compare two different voting systems. The following code is part of a very long DO loop in my code. When I run the script, the first time through the DO loop, it prints out the final sentence with the wrong value in the variable $remove_candidate. The program prints out “Doing 1.” and “Doing 2.”, showing that the first two if clauses are being activated, but not the ones after those. Therefore the value contained in the variable $remove_candidate should be the value contained in $candidate2_name, which, in the case I am running is, “Dem”. However, the final sentence prints out “SuperDem”, which is the value contained in $candidate1_name. (This is verified by the code that prints out the values contained in these variables.) Does anyone know why it would print out the value of $candidate1_name, rather than $candidate2_name?
if ($candidate1_irv_vote < $remove_number and $candidate1_out == 'No')
{ $remove_number = $candidate1_irv_vote;
$remove_candidate = $candidate1_name;
################# temporary ####################
echo "<p>Doing 1.</p>"; // Shouldn't do this 2nd time through
#########################################################
}
if ($candidate2_irv_vote < $remove_number and $candidate2_out == 'No')
{ $remove_number = $candidate2_irv_vote;
$remove_candidate = $candidate2_name;
################# temporary ####################
echo "<p>Doing 2.</p>";
#########################################################
}
if ($candidate3_irv_vote < $remove_number and $candidate3_out == 'No')
{ $remove_number = $candidate3_irv_vote;
$remove_candidate = $candidate3_name;
################# temporary ####################
echo "<p>Doing 3.</p>";
#########################################################
}
if ($candidate4_irv_vote < $remove_number and $candidate4_out == 'No')
{ $remove_number = $candidate4_irv_vote;
$remove_candidate = $candidate4_name;
################# temporary ####################
echo "<p>Doing 4.</p>";
#########################################################
}
if ($candidate5_irv_vote < $remove_number and $candidate5_out == 'No')
{ $remove_number = $candidate5_irv_vote;
$remove_candidate = $candidate5_name;
################# temporary ####################
echo "<p>Doing 5.</p>";
#########################################################
}
if ($candidate6_irv_vote < $remove_number and $candidate6_out == 'No')
{ $remove_number = $candidate6_irv_vote;
$remove_candidate = $candidate6_name;
################# temporary ####################
echo "<p>Doing 6.</p>";
#########################################################
}
if ($candidate7_irv_vote < $remove_number and $candidate7_out == 'No')
{ $remove_number = $candidate7_irv_vote;
$remove_candidate = $candidate7_name;
################# temporary ####################
echo "<p>Doing 7.</p>";
#########################################################
}
if ($candidate8_irv_vote < $remove_number and $candidate8_out == 'No')
{ $remove_number = $candidate8_irv_vote;
$remove_candidate = $candidate8_name;
################# temporary ####################
echo "<p>Doing 8.</p>";
#########################################################
}
if ($candidate9_irv_vote < $remove_number and $candidate9_out == 'No')
{ $remove_number = $candidate9_irv_vote;
$remove_candidate = $candidate9_name;
################# temporary ####################
echo "<p>Doing 9.</p>";
#########################################################
}
if ($candidate10_irv_vote < $remove_number and $candidate10_out == 'No')
{ $remove_number = $candidate10_irv_vote;
$remove_candidate = $candidate10_name;
################# temporary ####################
echo "<p>Doing 10.</p>";
#########################################################
}
############## temporary #################
echo "<p>candidate1_name: $candidate1_name</p>";
echo "<p>candidate2_name: $candidate2_name</p>";
echo "<p>candidate3_name: $candidate3_name</p>";
echo "<p>candidate4_name: $candidate4_name</p>";
echo "<p>candidate5_name: $candidate5_name</p>";
echo "<p>candidate6_name: $candidate6_name</p>";
echo "<p>candidate7_name: $candidate7_name</p>";
echo "<p>candidate8_name: $candidate8_name</p>";
echo "<p>candidate9_name: $candidate9_name</p>";
echo "<p>candidate10_name: $candidate10_name</p>";
######################################################
// Keep track of candidates that have been removed/voted out
if($remove_candidate = $candidate1_name)
{ $candidate1_out = "Yes";
####### temporary ################################
echo "<p>CANDIDATE1_OUT IS NOW YES</P>";
#################################################
}
elseif($remove_candidate == $candidate2_name)
{ $candidate2_out = "Yes";}
elseif($remove_candidate == $candidate3_name)
{ $candidate3_out = "Yes";}
elseif($remove_candidate == $candidate4_name)
{ $candidate4_out = "Yes";}
elseif($remove_candidate == $candidate5_name)
{ $candidate5_out = "Yes";}
elseif($remove_candidate == $candidate6_name)
{ $candidate6_out = "Yes";}
elseif($remove_candidate == $candidate7_name)
{ $candidate7_out = "Yes";}
elseif($remove_candidate == $candidate8_name)
{ $candidate8_out = "Yes";}
elseif($remove_candidate == $candidate9_name)
{ $candidate9_out = "Yes";}
elseif($remove_candidate == $candidate10_name)
{ $candidate10_out = "Yes";}
echo "<p>The candidate removed after round $round_number of voting is $remove_candidate.</p>";