FOR ... DO in SCL TIA Portal
Posted: Mon Jun 29, 2020 11:48 am
What is this instruction in SCL in TIA Portal
Limit is defined as a constant =7
What does this mean FOR #index := #LIMIT TO 1 BY -1 DO especially the part BY -1 DO
Limit to 1 means we start at 7,6,5,4,3,1 and move to 1, but i dont understand what this ( BY -1) mean does it tell it to reduce -1 each time
https://prnt.sc/t8fws2
Limit is defined as a constant =7
What does this mean FOR #index := #LIMIT TO 1 BY -1 DO especially the part BY -1 DO
Limit to 1 means we start at 7,6,5,4,3,1 and move to 1, but i dont understand what this ( BY -1) mean does it tell it to reduce -1 each time
https://prnt.sc/t8fws2
Code: Select all
(* Part 1 Sorting of data ******************************************************
Swaps adjacent pairs of values using the ”bubble sort”
method until the measured data buffer is correctly sorted. *)
REPEAT
#swap := FALSE;
FOR #index := #LIMIT TO 1 BY -1 DO
IF #sortbuffer[#index -1 ] > #sortbuffer[#index] THEN
#aux := #sortbuffer[#index];
#sortbuffer[#index] := #sortbuffer[#index -1 ];
#sortbuffer[#index -1] := #aux;
#swap := TRUE;
END_IF;
END_FOR;
UNTIL NOT #swap
END_REPEAT;
(* Part 2 Calculation of results ***********************************************
Calculates square root using standard function SQRT and
square using function SQUARE. *)
FOR #index := 0 TO #LIMIT BY 1 DO
#valr := INT_TO_REAL(#sortbuffer[#index]);
#resultr := SQRT(#valr);
#calcbuffer[#index].squareroot := REAL_TO_INT(#resultr);
#calcbuffer[#index].square := "SQUARE" (#sortbuffer[#index]);
END_FOR;