
There is a big bowl of M&M candies. There are red, yellow, green and blue M&Ms all mixed in the big bowl. If your job is to sort and separate and group the colored candies, how will you go about solving the problem?
Here is how most programmers would attempt to solve the problem :)
Get 4 containers and label them yellow, red, blue and green.
Pick each M&M from the big bowl
If Blue, put it in the “Blue” container
If Yellow, put it in the “yellow” container
If Red, put it in the “Red” container
If Green, put it in the “Green” container
Repeat from step 2 until big bowl is empty
Ignore the decision structures and the iterative process in this example, but instead focus on the 4 containers and their labels. The containers were brought in to hold M&Ms and also each container should contain only a specific colored M&M based on the label.
Similarly,
Variables help hold intermediate results, especially in a multi-step complex calculation.
The content of the variable depends on its data type. ( String, Numeric, Boolean, Date, etc)
The data type of a variable determines what type of calculations may be performed, arithmetic or string, etc.