December 2015
Intermediate to advanced
416 pages
7h 15m
English
CHAPTER 5
![]()
Guessing Games with Random Numbers and Loops
The last step before we start with graphics is learning how to loop a section of code. Most games loop. They repeat the same code over and over. For example, the number guessing game below loops for each guess that the user makes:
Hi! I'm thinking of a random number between 1 and 100.--- Attempt 1Guess what number I am thinking of: 50Too high.--- Attempt 2Guess what number I am thinking of: 25Too high.--- Attempt 3Guess what number I am thinking of: 17Too high.--- Attempt 4Guess what number I am thinking of: 9Too low.--- Attempt 5Guess what number I am thinking of: 14Too high.--- Attempt ...
Read now
Unlock full access