4 hours 19 minutes
hi and welcome back to the courts. Now. Hope you guys were doing well. And if you remember in the last video lecture or lab, we went over creating and finishing up our fair calculator program, in which we learned how to apply an implement if statements and work with some control structures or control float.
And in this video lecture we will be going over four loops in Java.
So I was always. I've listed out some objectives for you to follow the 1st 1 being that we would like to understand what four loops are and the fundamentals of four loops
understand why and when we would have to use them
as well as finally understand the syntax or the grammar of writing for loops in the real world and real life computer programs.
All right, so what are four loops
now? Looking at the formal definition, The four statement, which it is often referred to us, provides a compact way to iterated over a range of values. Now, if you don't know the meaning of iterating, that a century just means going over something.
And then it says, programmers often referred to it as a four loop because of the way in which it repeatedly loops until a particular condition is satisfied.
So essentially, what a four loop does is
it continues to run,
and there is usually a set arrange until it does runs, and then, once it reaches the end of that range or that condition than the loop terminates. Now, in order for us to properly first understand how four loops work or how they look,
it would be best to see an example. So here we have a for loop
and inside of four Luke, or this is the you could say this is the pseudo code or the structure of a four loop. And if you don't know what pseudo code means, that's basically a high level language to explain what you will be doing and what you have done in any sort of computer program.
So in this four Luke, we first have
the initialization part,
an initialization. That expression, essentially just initialize, is a loop,
and it's on Lee executed once, which is very important to remember, and it is executed as the loop begins.
Then we go on to the termination part.
So as soon as the termination parameter evaluates to false meaning as soon as we reach some sort of condition and the value of that condition is false, that is when the loop terminates and stops.
Finally, in order for us to reach a certain condition, we need thio increment,
our first parameter. So by incrementally our first parameter, it'll go up and literate, turn by turn until it reaches that condition where it has to terminate.
So just to clarify it again, the increment parameter executes after each iteration. Incremental or decry menting a value are both valid for four loops.
So in order for us to properly understand for loop, we will be going over a
count program in our next lab, you could say, And in this video lecture, just to summarize what we went over, we discussed what four loops are
when to use them and why we would need them
as well as how we can actually write four loops Now. I'd like to elaborate on the second point of it just before we finish off here.
The reason we need to use four loops is because let's say
there's a time in our program where we know for a fact that we're going to be running a certain
a question that we may ask the user, or we might have to do certain things for a set amount or for a set number of times. And whenever you see that you're being asked to do something for a set number of times, that's when something should click in your head. And you should realize that
yes, maybe considering or using four loops
would be very beneficial in that specific case. And it bent basically just goes back to the idea of control, flow and structure altering the flow of your program, allowing some additional functionality instead of just reading code from top to bottom or sorry. Instead of having your program read code from top to bottom,
you can add
all sorts of things, and that is essentially the goal of this marshal.
So as I mentioned in the next video lecture or lab, we will be going over a count program, and that's where we will learn more about four loops.
Thank you very much for watching, and, as always, if you have any questions at all, feel free to contact me via LinkedIn, and I'd be more than happy to answer any of your questions and I'll see you in the next video lecture
Sun Certified Java Programmer
Sun Certified Java Programmer practice exam will help to prepare for the Oracle Certified Associate ...