Processing: An Introduction to Programming by Jeffrey L. Nyhoff & Larry R. Nyhoff
Author:Jeffrey L. Nyhoff & Larry R. Nyhoff [Nyhoff, Jeffrey L.]
Language: eng
Format: azw3
Publisher: CRC Press
Published: 2017-05-19T04:00:00+00:00
Because the while statement creates repetition, it is also known as a while loop . In this chapter, we will work through several examples that illustrate the functionality of a while statement (loop).
USING the while Statement: Rolling a Die Repeatedly
Let’ s return to our Roll program from Chapter 3. Select File > Save As and resave this program as RollWhile .
Currently, our program consists of the following:
int roll;
roll = int( random(1, 7) );
println("Roll: " + roll);
When we run this program, we see console output like the following:
Roll: 2
If we keep running the program, it is only a matter of time before we see that a 6 is rolled:
Roll: 6
We can be certain of this because we know that the statement
roll = int( random(1, 7) );
will eventually assign the roll variable the value 6 if we repeatedly run the program.
Currently, our program simulates just a single roll of a die. Thus, if we wish to simulate multiple rolls of a die, we currently need to rerun the entire program. However, suppose that we would like to change this program into a game that will automatically keep repeatedly rolling the die as long as the roll is not a 6 (i.e., is a 1, 2, 3, 4, or 5). Once the roll is a 6, the repetition stops, and the game is over.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Modelling of Convective Heat and Mass Transfer in Rotating Flows by Igor V. Shevchuk(6200)
Weapons of Math Destruction by Cathy O'Neil(5778)
Factfulness: Ten Reasons We're Wrong About the World – and Why Things Are Better Than You Think by Hans Rosling(4454)
Descartes' Error by Antonio Damasio(3137)
A Mind For Numbers: How to Excel at Math and Science (Even If You Flunked Algebra) by Barbara Oakley(3075)
Factfulness_Ten Reasons We're Wrong About the World_and Why Things Are Better Than You Think by Hans Rosling(3025)
TCP IP by Todd Lammle(2982)
Applied Predictive Modeling by Max Kuhn & Kjell Johnson(2857)
Fooled by Randomness: The Hidden Role of Chance in Life and in the Markets by Nassim Nicholas Taleb(2833)
The Tyranny of Metrics by Jerry Z. Muller(2818)
The Book of Numbers by Peter Bentley(2744)
The Great Unknown by Marcus du Sautoy(2516)
Once Upon an Algorithm by Martin Erwig(2454)
Easy Algebra Step-by-Step by Sandra Luna McCune(2433)
Lady Luck by Kristen Ashley(2386)
Practical Guide To Principal Component Methods in R (Multivariate Analysis Book 2) by Alboukadel Kassambara(2357)
Police Exams Prep 2018-2019 by Kaplan Test Prep(2332)
All Things Reconsidered by Bill Thompson III(2241)
Linear Time-Invariant Systems, Behaviors and Modules by Ulrich Oberst & Martin Scheicher & Ingrid Scheicher(2210)
