What is a PLC?

If you are learning about PLCs for the first time, start by understanding how a PC and a PLC differ.
Both have a CPU that performs calculations and memory that holds data.
A PC mostly completes its work inside the computer, such as processing text and images.
A PLC, on the other hand, receives information from the real world and uses that data to move real-world equipment.
That is why, in addition to the main unit, a PLC has an input unit that receives signals from outside and an output unit that sends signals out.

Let's express what a PLC does as a formula.
If the input data from sensors and buttons is Xn and the output data that operates lights and solenoid valves is Yn, writing a PLC program means defining this function F .

$$Y_0, Y_1, Y_2, \dots, Y_{15} = F(X_0, X_1, X_2, \dots, X_{15})$$

Also, while the power is on, a PLC repeats the processing defined in the ladder over and over.
You do not write a loop in a PLC program, but the program keeps running.
Each time the loop runs, it outputs Y0, Y1, Y2... according to the values of the inputs X0, X1, X2... at that moment.
Written as a formula, it looks like this:

$$\begin{array}{l} \mathtt{while\ True:} \\ \quad Y_0, Y_1, Y_2, \dots, Y_{15} = f(X_0, X_1, X_2, \dots, X_{15}) \end{array}$$

That is a brief explanation of PLCs.
Next, let's look at ladder logic, the way PLCs are programmed.