Time
4 hours 19 minutes
Difficulty
Beginner
CEU/CPE
4

Video Transcription

00:00
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.
00:20
And in this video lecture we will be going over four loops in Java.
00:26
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
00:37
understand why and when we would have to use them
00:42
as well as finally understand the syntax or the grammar of writing for loops in the real world and real life computer programs.
00:54
All right, so what are four loops
00:57
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.
01:14
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.
01:26
So essentially, what a four loop does is
01:30
it continues to run,
01:32
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,
01:52
it would be best to see an example. So here we have a for loop
01:56
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.
02:14
So in this four Luke, we first have
02:16
the initialization part,
02:20
an initialization. That expression, essentially just initialize, is a loop,
02:25
and it's on Lee executed once, which is very important to remember, and it is executed as the loop begins.
02:34
Then we go on to the termination part.
02:38
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.
02:51
Finally, in order for us to reach a certain condition, we need thio increment,
02:58
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.
03:10
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.
03:23
So in order for us to properly understand for loop, we will be going over a
03:30
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
03:40
when to use them and why we would need them
03:45
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.
03:54
The reason we need to use four loops is because let's say
03:59
there's a time in our program where we know for a fact that we're going to be running a certain
04:04
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
04:21
yes, maybe considering or using four loops
04:25
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,
04:45
you can add
04:46
all sorts of things, and that is essentially the goal of this marshal.
04:49
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.
04:59
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

Up Next

Introduction to Java

In this course, you will learn Java starting with the fundamental and key concepts that have made it become so powerful and widely used around the world for personal and industry projects. Some concepts covered in this course are the following: Inheritance, Encapsulation, Polymorphism, and Abstraction.

Instructed By

Instructor Profile Image
Salman Haider
Cyber Security Assessnent Analyst at Bank of Canada
Instructor