Not let's look at an authority that you can go for straight rent while statement or why loop a while 2
loop like a for loop is an education statement. 3
You should use follow up if you know how many times to look otherwise you should go for it while. 4
Why Lopez only condition expression on here is a general form. 5
As long as a condition expression is true the body of y look keeps getting executed. 6
So there is no initialization part. 7
Similarly there is not an expression to all that can be included in the body offwell There is also a 8
variation of vyle statement called blue eyed statement you would use it if the body of Weil must run 9
at least once and here is the syntax. 10
As you can see the body of Weil is followed by the condition expression so the body gets executed at 11
least once subsequently the body keeps getting executed on the commission expression is false not do 12
one statement and with the semicolon Otherwise you get a compilation error here's a good example where 13
Deuel is used. 14
Let's if you want to write some simple logic to perform some action based on user's input if you separate 15
what's a positive number. 16
We perform the action. 17
Otherwise the user is asked to re-enter that number. 18
So we need to first collect the input from user and then check if the input is positive or not. 19
This can be achieved using a do look as shown here. 20
The user input collection is done in the body and the while condition checks if and don't input is positive 21
or not so if they use it and there's zero or a negative number then the while condition would be true 22
and the user will be prompted to re-enter that number. 23
This can be use under the user enters a positive number at which time the while condition fails on the 24
intended action is performed. 25
Not let's look at in finite look which basically loops infinitely. 26
That is it loops forever. 27
For example let's consider a company which wants to send marketing e-mails every morning at Adium and 28
this can be achieved using a while loop as shown here that is a condition expression would always be 29
true and hence a body of the while loop keeps repeating forever but with each iteration a check is made 30
if the current time is 8 a.m.. 31
If that's the case then emails are standard by invoking sending mother. 32
Otherwise we continue to look this can also be you'll be using a frontal lobe as shown here. 33
As you can see to simulate an infinite loop. 34
The parenthesis does not include any of the expressions. 35
It includes all the semi-colons generally when implementing in fun I Cope's most people prefer while 36
loops or follows a semantically while loops are considered to be more clear. 37
However that's the case for infinite blocks. 38
But in all other situations if both front and why Looks are applicable then a for loop is preferable 39
. 40
This is also recommended by one of the effective July dumps and will be discussed later on that's about 41
it. 42
That's all there is to why Lopes