On PLCs every variable is declared first with a fixed type (INT, DINT, REAL, BOOL, STRING) and assigned with :=. Python and JavaScript infer the type and assign with =; C/C++, C# and Java are typed like a PLC but with other names (INT = 16-bit short, DINT = 32-bit int).
The logic is the same but the spelling changes: PLCs compare with =, not-equal is <>, they use AND/OR/NOT and close the block with END_IF. Software compares with == (=== in JavaScript), not-equal is != and the block lives in braces or indentation (Python, with elif).
It is the heart of state machines (steps 0, 10, 20…). The PLC CASE runs one branch only and accepts lists (20, 21) and ranges (90..99); in C, C++ and JavaScript a switch without break falls through, C# forces break, Java has the arrow form and Python uses match since 3.10.
The PLC FOR includes the end bound: FOR i := 0 TO 9 runs 10 times. In Python range(10) stops at 9 (10 is excluded), while C, C#, Java and JavaScript repeat while i < 10 is true: translating “0 TO 10” into “i < 10” silently drops the last element.
WHILE repeats while the condition is true, REPEAT…UNTIL (do…while in software) at least once. On a PLC the whole loop runs inside one scan: if you wait for an input inside a WHILE the program hangs and the cycle-time watchdog stops the CPU. Always add a safety limit.
A function takes parameters and returns a value. In SCL and IEC the return value is assigned to the function name and parameters are passed by name (Price := 50.0); Logix uses an Add-On Instruction; software uses return, with default values in Python, JavaScript, C++ and C# (Java uses overloads).
PLC arrays have a fixed size and declared bounds (Array[0..4] or [1..5]): an out-of-range index can stop the CPU. In software indexes always start at 0, the last one is length - 1 and lists such as list, vector, List or ArrayList can grow at runtime.
PLC strings have a maximum length (STRING[40], 82 characters in Logix), are joined with CONCAT and positions start at 1 (FIND returns 0 when not found). Software uses + or interpolated strings, positions start at 0 and “not found” is -1.
A TON (on-delay timer) never blocks the PLC: you call it every scan and its output Q turns true once the input has stayed on for the preset time PT. The classic software mistake is sleep: time.sleep or Thread.sleep freeze the whole program; the correct equivalent compares the elapsed time on every pass (or uses setTimeout/async).
A button held down stays true for hundreds of scans: to count a single press you need the rising edge (R_TRIG in SCL and IEC, OSRI in Logix), true for one scan only. In software you do it by hand: remember the previous state and check “true now and false before”.
An analog input arrives as a raw number (0…27648 on the most common 4–20 mA or 0–10 V cards) and must be converted to engineering units: y = (x − in_min) × (out_max − out_min) ÷ (in_max − in_min) + out_min, then clamped. Beware of integer division, which truncates the decimals.
Reading or writing a single bit of a status WORD is daily work in automation: PLCs have direct bit access (Status.%X3 in SCL, Status.3 in Logix and IEC). Software uses masks and shifts: (status >> 3) & 1 to read, |= to set, &= ~ to clear, always with parentheses.
A structure groups the data of a real object (name, speed and state of a motor). On PLCs it is a user data type (UDT) and assigning it copies the whole content; in Python, JavaScript, C# and Java classes are references: assigning does not copy, both variables point to the same object. C/C++ and C# structs, instead, are copied like on a PLC.
PLCs have no exceptions: you prevent the error with guards (divisor not zero, index within bounds) and report it with an alarm bit. Software uses try/catch (try/except in Python), but beware: in JavaScript and with floating-point numbers dividing by zero gives Infinity with no exception, and in C/C++ integer division by zero is undefined behaviour.