While Loops
A While Loop is a pre-test loop.
- In a pre-test loop, conditions of the loop are tested before the code is run.
- In a While Loop, a statement or statements are repeated while a condition is true.
- The loop stops when the condition evaluates to false.
|
NOTE: A single execution of a loop is called an iteration
While Loop Syntax:
While Loop Syntax:
Example:
What is the output of this code? (Code uploaded to github)
What is the output of this code? (Code uploaded to github)
What is the output to this code?
What is the output to this code?
What is the output to this code?
TRY IT YOURSELF
Create a sketch that displays stars for any given rating.
This sketch must:
For example: if the user inputs a rating of 2, your program should output: **
This sketch must:
- Ask the user for a rating between 1 and 5.
For example: if the user inputs a rating of 2, your program should output: **