0

So I have a long code, but when I run it, I get the error: "Parse error: syntax error, unexpected end of file"

I have googled quite a bit, and it seems to me that most often the culprit is a missed bracket. Well, I think the problem here is too. But let me elaborate a bit:

Before I get the code here online, here is a brief overview of my code:

  • primary for loop starts
  • some if and other miscallonous lines
  • secondary for loop starts (while the primary for loop is still on going)
  • secondary for loop ends
  • again, some miscallonous lines
  • tertiary loop starts (primary loop still running again)
  • tertiary loop ends
  • some extra lines
  • primary loop ends

And here is the funny thing which I think causes the mistake. So in the primary loop there are two other for loops, which I will name the secondary and tertiary loop. If I place the ending bracket for the primary loop (a "}") BEFORE the tertiary loop starts, the starting bracket and the ending bracket of the primary loop connect (meaning, if you click on one of the brackets, both will light up green, thus they connect). However, if I place the ending bracket AFTER the tertiary loop starts, the starting bracket of the primary loop will NOT connect with it. It doesn't matter if I cut the tertiary loop before the secondary loop (thus making the tertiary loop the secondary and vice versa), the ending bracket of the primary loop will not connect with the starting bracket if it is placed AFTER the tertiary (the third) loop.

I have gone through my code several times. Besides these two brackets, all other brackets connect with each other. I don't see any solitary brackets. Maybe it is some kind of internal error, that it should work theoretically but that it doesn't in reality. Frankly I am not a programming genius so that is why I post this problem here :P.

Here's the code (I had to put it in a JavaScript/HTML/CSS snippet preview because the "code sample" messes the text up as it thinks every bracket is a new code sample):

for ($p = 0; $p<=1000;$p++)
{
//the above starting bracket should connect with the bracket all the way down
               $ale=$ale*(1+($ale0-$levensverwachting)/(10*$ale0));

               $tfr=$tfr*(1+($tfr0-$realtfr)/(10*$tfr0));
                        
$grens=15+(20/$tfr);

if ($grens==30)
{
$grens=30;
}

if ($grens==18)
{
$grens=18;
}

$totaalgeborenen=0;
$houop=0;
$newfactortotaal=1;
$newfactor=1;
$medgb0=1;
$newfactorAr=array();
                        for ($v=15;$v<=44;$v++)
                        { 
                               $vbev=$vbev+0.5*$ageAr[$v];
                                        if ($v<= $grens)
                                        {
                                        $newfactor=($v-14)*($tfr/30)/($grens-14);
                                        }
                                        if ($v>$grens)
                                        {
                                        $newfactor=($tfr/30)-($v-$grens)*($tfr/30)/($grens-45);
                                        }
                                $newlt=$ageAr[$v]*0.5*$newfactor;
                                
                                $totaalgeborenen=$totaalgeborenen+$newlt;
                               
                               if ($p>$sy-50)
                               {
                               $juist="tfr" . $v; 
                               array_unshift(${"$juist"},$newfactor); 
                               }         
                                //tfr+med geb
                                $totalfertilityrate=$totalfertilityrate+$newfactor;
                                $medgb0=$medgb0+($newfactor);
                                
                                if ($medgb0==1)
                                {
                                $medgb=$v;
                                $medgb0=1;
                                }
                                
                                array_push($newfactorAr,1+$newfactor);
                                
                                if (array_product($newfactorAr)>=1.5 && $houop !=1)
                                {
                                $oudfertility=array_product($newfactorAr)/$newfactor;
                                $goedjuiste=1.5/$oudfertility;
                                $aob=$v-($newfactor/$goedjuiste)+1;
                                $houop=1;
                                }

                           }
                           
                                
$vbevorign =$vbev;         
                     
$newage=$totaalgeborenen;
$totaalgeborenen=0; 

$realtfr=$totalfertilityrate;
$totalfertilityrate=0;
$newfactortotaal=1;

$actualnew = round($newage*(1-$imr/1000));
$ageArBG = array_sum($ageAr);
$vbev=0;

array_unshift($ageAr,$actualnew);
array_unshift($ageOrignal1,$actualnew); 

        $echtebev0 = array_sum($ageAr);
        
        $totaalgehalte=1-$imr/1000;
        $special2=0;
        $gehalte=1;        
        $optellen=0;
        

 for ($n2 = 0;$ageAr[$n2]>=1;$n2++)
 {
   
                        $ageN=$ageAr[$n2];
        
                        if ($n2 != 0 && $ageAr[$n2]>=1)
                        {
                                if ($ale<=7)
                                {
                                $ale=7;
                                }
        
                                $co=pow(M_E,($ale-27.215)/-3.999);
                                $bes=log(105/$co)/log(110);

                                if ($co*pow($n2,$bes)<100)
                                {
                                $ovka=0.5*log(100-$co*pow($n2,$bes),10);
                                }
                                else
                                {
                                $ovka = 0;
                                }
                                if ($ovka<=0)
                                {
                                $ovka=0;
                                }
                                $ageAr[$n2]=$ageAr[$n2]*$ovka;

                        }
        
        
                        if ($n2>0 && $n2<5)
                        {
                        $ageBEF=$ageBEF+$ageAr[$n2];
                        $ageAr[$n2]=$ageAr[$n2]-((5-$n2)/10)*(0.5*$imr/1000)*$ageAr[0];
                        $ageAF=$ageAF+$ageAr[$n2];
                        }
        
    
                                if ($ageAr[$n2]<1)
                                {
                                $ageAr[$n2]=0;
                                }
                
                                  if ($ageAr[$n2]>=1)
                                  {
                                  $gehalte=$ageAr[$n2]/$ageN;
                  
                                  $totaalgehalte=$totaalgehalte*$gehalte;
                                  $optellen=$optellen+$totaalgehalte;
                                  }
                  
                                  if ($ageAr[$n2]<1)
                                  {
                                  $levensverwachting=round($optellen,2);
                  
                                  }
                  
                                        $ageD=$ageN-$ageAr[$n2]; 
                                        $ageDtot = $ageDtot + $ageD;
                                        $lvAgeD=$ageD*$n2;
                                        $lvAgeDtot=$lvAgeDtot+$lvAgeD;

            }
            
            
            

        
$special2=0;
$totaalgehalte=1-$imr/1000;
$optellen=0;
        
        //child mortality
        $childdood=$ageBEF-$ageAF;
        $childmortality=round(1000*($childdood+$newage*($imr/1000))/($newage),2);
        $ageBEF=0;
        $ageAF=0;
 

 $ageArEN=array_sum($ageAr);
 //$groei=round(100*($ageArEN/$ageArBG)-100,2);
 $br = round(1000*$newage/$ageArEN,1);
 $gestorven = $ageDtot+($newage*$imr/1000);
        $ageDtot =0;
        $dr = round(1000*($gestorven)/$ageArEN,2);

        $realale=$lvAgeDtot/$gestorven;
        $realelv=$lvAgeDtot/($gestorven-$newage*$imr/1000);
        $lvAgeDtot=0;
             
 for ($q=0;$q<=14;$q++)
 {
 $onder16=$onder16+$ageAr[$q]; 
 }

 $onder15perc=round(100*$onder16/$ageArEN,2);
        $echtebev = array_sum($ageAr);
        
        if ($p !=$sy)
        {
        $echtebev = array_sum($ageAr);
        }
        else
        {
        $echtebev = array_sum($ageAr);
        }
        
        
        $birthrate = round(1000*($newage)/$echtebev,1);
        //$dr = $br-$groei*10;
        $dr=round(1000*($gestorven)/$echtebev,1);
        $nettogroeiabs=$newage-$gestorven-$emtot+$lalatot;
        
        $groei=round(100*(array_sum($ageAr)/(array_sum($ageAr)-$nettogroeiabs)-1),2);
        
        
        $lengte = count($ageAr);
        $jongeren = 0;
        $adults = 0;
        for ($io = 0; $io<=$lengte;$io++)
        {
                if ($io<=14)
                {
                $jongeren = $jongeren+$ageAr[$io]; 
                }
                
                if ($io>14 && $io<=64)
                {
                $adults=$adults+$ageAr[$io];
                }
        }
        
        $jongerenperc = round(100*$jongeren/array_sum($ageAr),2);
        $adultsperc = round(100*$adults/array_sum($ageAr),2);
        //$groeijaar = round($echtebev/$echtebev0,2);        
        
        $medianpop=0;
        if ($pop!=0)
        {
                for ($rt = 0;$rt<=$l;$rt++)
                {
                        if ($medianpop<0.5*array_sum($ageAr))
                        {
        
                        $medianpop=$medianpop+$ageAr[$rt];
                        }
                        else
                        {
                        $medianage = $rt-round(($medianpop-0.5*array_sum($ageAr))/$ageAr[$rt],2)-1;
                        $rt=$l+1;
        
                        }
                }
        }
        
        if ($p==999)
        {
        $elderly=100-$jongerenperc-$adultsperc;
        echo "Total Fertility Rate: " . $realtfr . "<br>Birth rate per thousand: " . $birthrate . "<br>Infant mortality rate: " . $imr . "<br>Child mortality rate: " . $childmortality . "<br>Life expectancy: " . $levensverwachting . "<br>Death rate per thousand: " . $dr . "<br>Growth rate in percent: " . $groei . "%<br>Median age: " . $medianage . "<br>People 14 years or younger: " . $jongerenperc . "%<br>People between 15 and 64 years: " . $adultsperc . "%<br>People 65 years or older: " . $elderly;
        }        


} 
//the above ending bracket should connect with the bracket all the way up
  • I can not find anything wrong with your code – halojoy Dec 23 '17 at 14:05
  • There are no syntax errors in the posted excerpt. The formatting / syntax style is hardly helpful to investigate. Also such questions ought to mention the used IDE. Otherwise we'd assume you didn't bother, and just laugh at your inept tinkering. – mario Dec 23 '17 at 14:13

0 Answers0