Case..of: Fatal error lazarus / 61-Beginners ---------------------------------------------------------------------- RNBW · 2017-02-08 11:34 I have progressed my program from yesterday's post (Beginners: Readln; doesn't stop program from exiting) but have come up against a Fatal syntax error that I don't understand. When compiling, it fails with the following (both at line 118). SimpleBeam_Dev01_04.pas(118,25) Error: label used but not defined “2” SimpleBeam_Dev01_04.pas(118,25) Fatal: Syntax error, “END” expected but “identifier WL” found. I don't understand why either error has occured.  Can someone explain and point me in the right direction. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //**************************************************// SimpleBeam_Dev01_04.pas// Analysis of Single Span Simply Supported Beam// Introduce Calculation of Shear Forces Along Beam// Status: Fatal error at line 118,25//************************************************** program SimpleBeam_Dev01_04; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes, SysUtils;  var  j,k,ns,nl: Integer;  L, rl,rr,ra,rb: Double;  vk,mk,z: Double;  s, t: Double;  z1,wl,z2: Double;   vs: array[1..51] of Double;  //will allow up to 51 sections  ms: array[1..51] of Double;  W: array[1..20] of Double;   //will allow up to 20 loads  a: array[1..20] of Double;  c: array[1..20] of Double;  tl: array[1..20] of Byte;  begin   Writeln('SINGLE SPAN SIMPLY SUPPORTED BEAM PROGRAM');   Writeln;   Write('ENTER NUMBER OF SECTIONS TO BE CONSIDERED ON THE BEAM: ');   Readln(ns);   Write('ENTER NUMBER OF LOADS ON THE BEAM: ');   Readln(nl);    //Initialize vs[k] and ms[k] elements to zero   for k:= 1 to ns do     begin       vs[k] := 0;       ms[k] := 0;     end;    //Initialize W[j], a[j] and c[j] elements to zero   for j := 1 to nl do     begin       W[j] := 0;       a[j] := 0;       c[j] := 0;     end;    //Enter span of beam (L)   Write('ENTER SPAN OF BEAM (metres) = ');   Readln(L);    //Loop for Load Information Input   Writeln;   Writeln('THE POSSIBLE LOAD TYPES ARE:-');   Writeln('1..POINT LOAD (PL)');   Writeln('2..UNIFORMLY DISTRIBUTED LOAD (UDL)');   Writeln('3..TRIANGULARLOAD, SLOPING LEFT (TLL)');   Writeln('4..TRIANGULAR LOAD, SLOPING RIGHT (TLR)');   Writeln;   for j:= 1 to nl do     begin       Writeln('LOAD No: ',j);       Write('ENTER LOAD, W (Kn): ');       Readln(W[j]);       Write('ENTER TYPE OF LOAD (1,2,3 OR 4): ');       Readln(tl[j]);       Write('ENTER DISTANCE OF START OF LOAD FROM LEFT SUPPORT (metres): ');       Readln(a[j]);       Write('ENTER LENGTH OF LOAD COVER ( 0 IF PL) (metres): ');       Readln(c[j]);       Writeln;        //Calculate Reactions       case tl[j] of            1: s := a[j];            2: s := a[j] + c[j]/2;            3: s := a[j] + 2*c[j]/3;            4: s := a[j] + c[j]/3;       end;        t := L - s;        rl := W[j] * t/L;       rr := W[j] - rl;        ra := ra + rl;       rb := rb + rr;        Writeln('RL = ', Format('%.3f',[rl]), ' kN');       Writeln('RR = ', Format('%.3f',[rr]), ' kN');       Writeln;       Writeln('RA = ', Format('%.3f',[ra]), ' kN');       Writeln('RB = ', Format('%.3f',[rb]), ' kN');     end;        //Calculate Shear Forces Along Beam       for j := 1 to nl do         begin            vs[1] := vs[1] + rl;             for k := 2 to ns do                begin                z := (k-1) * L/(ns-1);                  case tl[j] of                   1: if (z <= a[j]) then                           vk := rl;                        else                           vk := -rr;                   2: wl := W[j] * z1/c;                        vk := rl - wl;                    end;                end;         end;    Writeln;   Write('PRESS ANY KEY TO END PROGRAM');   Readln;end.  Thank you, in anticpation. ---------------------------------------------------------------------- JdeHaan · 2017-02-08 11:44 case tl[j] of                      1: if (z <= a[j]) then                            vk := rl  // remove ;                         else                            vk := -rr;                      2: begin                            wl := W[j] * z1/c;                            vk := rl - wl;                          end; ---------------------------------------------------------------------- jacmoe · 2017-02-08 11:46 You need begin / end pairs in your switch case section. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i                 case tl[j] of                     1: begin                          if (z <= a[j]) then                              vk := rl;                          else                              vk := -rr;                        end;                     2: begin                          wl := W[j] * z1/c;                            vk := rl - wl;                          end;  ..JdeHaan beat me to it. ---------------------------------------------------------------------- Handoko · 2017-02-08 11:48 Oops, I'm too late. But no harm to post my explanation. Welcome back RNBW. I haven't tested your code, but I notice something that may be the problem. The error message pointed to line 118. And here is the code: Quote               1: if (z <= a[j]) then                      vk := rl;                   else                      vk := -rr; Can figure out the problem? If you can't here is the answer: There should be no ";" sign before else. Read more here: http://wiki.freepascal.org/Else ---------------------------------------------------------------------- Lupp · 2017-02-08 11:50 The semicolon at the end of line 115 closes the if-statement as an incomplete alternative. (No error, but obviously not what you wanted.) Thus the else in line 116 is parsed as a case else. (Do if no case- label matched.) Behind the case else no further case is allowed. Therefore the 2: in line 118 is supposed to be a target for GoTo statements. (Yes that's still supported. Yes, unsigned integers are allowed as labels. That's inheritage from ancestors of the 1950es.) Labels to GoTo must be declared in Pascal using the reserved word label. The following nonsense code is compiled without an error: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1;label 2;begin  2:  GoTo 2end. ---------------------------------------------------------------------- Handoko · 2017-02-08 12:00 +1 Lupp ---------------------------------------------------------------------- RNBW · 2017-02-08 18:07 Thank you all.  That's got me over that hurdle and i've now been able to progress a little further.  I have come up against another problem, which I'm trying to work out at present.  It's in the mathematics and its logic, so I'm hoping to sort it out myself.