This is a while loop. The code is done while the condition is true. The code that is done is enclosed in { }. Note that this program has three parts: Housekeeping which sets things up and takes in input. Processing which is the loop and the code inside the loop. Wrapup which prints out the end message after processing is complete.
There are three things that control the loop. I initialize ct at 1. I increment ct inside the loop so it changes. The condition on the loop compares ct to the data_input information. Eventually since I increment ct with every pass, ct will stop being less than or equal to data_input and processing will stop.
When I put in 1 then the loop gets executed because ct with 1 is less than or equal to data_input with 1. Then I increment ct to 2. The loop will not process again because ct of 2 is not less than or equal to data_input of 1. The loop is not entered and the statement after the loop is executed.
I entered a 0 for data_input so the loop does not get executed because the 1 in ct is not less than or equal to the 0 in data_input.
The do loop is structured differently. The loop is always executed once because the checking is at the bottom and so checking is not done unitl the loop has executed once.
If I enter either a 1 or a 0 the loop will get executed once and ct will move up to 2 prior to checking. The check will compare ct at 2 with data_input at 1 or 0 and the loop will not be executed again. Note that it will always be executed once.
In class exercise is to add an if statement to test to see which player won or if it is a tie.
Looking back at another program for a sample of using the if.