The first thing I have to wonder is why are you trying to learn this language? This is a pretty archaic programming language, and I can't think of anyplece where it's used, other than as a curiosity.
Nevertheless, the G value is the control of the loop. At the top, G is set to zero. It has to be set to a value to make this work. A is set to 15 for the example. You can set A to anything you like.
Now, the program waits until you type in a number.If the number you type is smaller or larger than A (15), you get the appropriate message.
The value of G stays at zero, because we want the loop to continue until the user gets the number right (which will happen as long as G==0). Once they hit it, G is set to 1, and they get the success message. Now that G == 1, the program ends because the condition has been met.
In most languages, this would look something like this pseudocode. This is a much simpler way of seeing it:
A = 15;
G = 0;
D = ''; (D is null)
while (G is zero) {
print "Enter a number:";
read input into D;
if (D is more than A) {
print "Your number is too high"
} else if (D is less than A) {
print "Your number is too low"
} else if (D equals A) {
print "Your number is correct"
set G to 1;
}
}
Loops are just a way of repeating something until a condition is met or a range of values has been tested.
"while" statements run until a certain condition (G equals 1) is met.
"If" statements look at the value of something, and act based on that value. An if statement can have a number of different actions to take, all based on different conditions. You can also do this with a "switch" statement.
"for" statements act on a range of values. Say you wanted to know the square of all number from 1 through 20. A "for" statement would perform the calculation and display it through the whole range, then stop at the last number.