Sentinel-controlled while loop - Java tutorial with a PRACTICAL example
Hi and welcome back to this channel
Today we are going to have a look at another form that a while loop may take in a program.
Previously we talked about counter-controlled loops
In this video particularly we will talk about another form of while loops which is called the Sentinel-controlled while loop
This while loop form is often used when you do not know exactly how many times a set of statements needs to be executed
But instead, you do know that the statements need to be executed until a special value is met.
This special value is called a sentinel
The portion of code on the screen is a typical example of a Sentinel-controlled while loop
int sentinel = 100;
int score =0;
while (score != sentinel) {
System.out.print( score + “ “);
score = score + 20;
}
In this example, we have started by declaring and initializing the Sentinel variable, here sentinel
Next, we have initialized the loop control variable score as well
In the while statement, we are using the loop condition to test the loop control variable score against the Sentinel variable sentinel
As long as, the loop control variable is different from the sentinel then the action statement will execute
The first action statement will output the values of the variable score
And the second action statement will increment the value of the variable score by 20, whenever the loop condition is met
Let’s take another example
Suppose we want to create a program that will read integer values and sum them up.
But we do not know exactly how many numbers the user needs to type in.
So, in our program, we are going to determine an integer value that will be considered a Sentinel and that value will be used to mark the end of the input data.
In this program, I want the user to input data from the keyboard
So, I will create an input object
static Scanner console = new Scanner(System.in);
Next, I will declare and initialize the Sentinel variable
I prefer it to be a static variable
static final int SENTINEL = 10;
public static void main(String[] args)
{
Next, I need to declare the various variables that will be used in this program
The first variable will be used to store the input numbers by the user
int number;
The second variable will hold the sum of all the numbers inputted by the user
int sum = 0;
The third variable will be the loop control variable
int counter = 0;
Next, we will write an output statement that will prompt the user to input the integer number
System.out.println("Enter consecutive number and stop at " + SENTINEL);
Let’s write the input statement
number = console.nextInt();
After, we will write the while loop statement
The loop condition will test the variable number against the variable Sentinel
whi
...
https://www.youtube.com/watch?v=5wNEuIEoM0Q
Project Management - 5 Benefits Of Professional Trainings & Certifications In Project Management
I am trying to grow my channel, so if you find this video useful please subscribe & hit the notification bell :)
Thanks for watching and I hope you liked and learned something new !!!!!
#projectmanagementtutorial
#codingriver
...
https://www.youtube.com/watch?v=SbdJ6JS91BA
PRODUCT OWNER Interview Q/A #2 - What are the main responsibilities of a Product Owner?
Mastering the Product Owner Role: Main Responsibilities and Tips for a Successful Interview"
Are you aspiring to become a Product Owner and wondering what the main responsibilities of this role are? Look no further! In this video, we'll dive into the key duties and skills required to excel as a Product Owner, and provide you with insider tips on how to ace your next interview.
We'll cover essential responsibilities such as defining and prioritizing product features, collaborating with stakeholders, and ensuring the development team delivers high-quality products that meet customer needs. We'll also discuss the importance of effective communication, strategic thinking, and product vision in this role.
With our expert advice, you'll gain the confidence and knowledge needed to impress your interviewer and stand out as a top candidate for any Product Owner position.
So, what are you waiting for? Tune in and take your first step towards mastering the Product Owner role!
#productowner
#responsibilities
#interviewtips
#productmanagement
#careeradvice
...
https://www.youtube.com/watch?v=i1SNKccFDCI
#1 This Is Why You Should Learn To Code With PYTHON In 2022
#codingriver
#pythonprogramming
#learntocode
...
https://www.youtube.com/watch?v=Xoc1Jh26Vmg