Control flow execution with while and do-while

Salesforce Development Using Apex Control flow execution with while and do-while
20 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€48.10
List Price:  €67.35
You save:  €19.24
£39.88
List Price:  £55.83
You save:  £15.95
CA$71.97
List Price:  CA$100.76
You save:  CA$28.79
A$80.16
List Price:  A$112.23
You save:  A$32.07
S$67.96
List Price:  S$95.14
You save:  S$27.18
HK$388.27
List Price:  HK$543.62
You save:  HK$155.34
CHF 45.02
List Price:  CHF 63.04
You save:  CHF 18.01
NOK kr569.59
List Price:  NOK kr797.48
You save:  NOK kr227.88
DKK kr358.90
List Price:  DKK kr502.49
You save:  DKK kr143.58
NZ$88.63
List Price:  NZ$124.10
You save:  NZ$35.46
د.إ183.61
List Price:  د.إ257.07
You save:  د.إ73.45
৳5,972.19
List Price:  ৳8,361.55
You save:  ৳2,389.35
₹4,258.89
List Price:  ₹5,962.79
You save:  ₹1,703.89
RM224.30
List Price:  RM314.04
You save:  RM89.74
₦77,378.02
List Price:  ₦108,335.42
You save:  ₦30,957.40
₨13,924.71
List Price:  ₨19,495.71
You save:  ₨5,570.99
฿1,707.62
List Price:  ฿2,390.81
You save:  ฿683.18
₺1,762.36
List Price:  ₺2,467.44
You save:  ₺705.08
B$310.08
List Price:  B$434.14
You save:  B$124.06
R926.14
List Price:  R1,296.68
You save:  R370.53
Лв94.05
List Price:  Лв131.68
You save:  Лв37.62
₩72,995.06
List Price:  ₩102,198.93
You save:  ₩29,203.86
₪183.24
List Price:  ₪256.56
You save:  ₪73.31
₱2,921.84
List Price:  ₱4,090.81
You save:  ₱1,168.96
¥7,853.11
List Price:  ¥10,994.99
You save:  ¥3,141.87
MX$1,006.35
List Price:  MX$1,408.98
You save:  MX$402.62
QR182.19
List Price:  QR255.09
You save:  QR72.89
P691.26
List Price:  P967.82
You save:  P276.56
KSh6,461.20
List Price:  KSh9,046.20
You save:  KSh2,585
E£2,544.49
List Price:  E£3,562.49
You save:  E£1,018
ብር6,361.91
List Price:  ብር8,907.19
You save:  ብር2,545.27
Kz45,590.88
List Price:  Kz63,830.88
You save:  Kz18,240
CLP$49,514.09
List Price:  CLP$69,323.69
You save:  CLP$19,809.60
CN¥364.84
List Price:  CN¥510.80
You save:  CN¥145.96
RD$3,032.23
List Price:  RD$4,245.36
You save:  RD$1,213.13
DA6,760.37
List Price:  DA9,465.07
You save:  DA2,704.69
FJ$115.98
List Price:  FJ$162.39
You save:  FJ$46.40
Q385.05
List Price:  Q539.11
You save:  Q154.05
GY$10,455.66
List Price:  GY$14,638.77
You save:  GY$4,183.10
ISK kr6,980.10
List Price:  ISK kr9,772.70
You save:  ISK kr2,792.60
DH502.81
List Price:  DH703.98
You save:  DH201.16
L922.32
List Price:  L1,291.33
You save:  L369
ден2,959.81
List Price:  ден4,143.97
You save:  ден1,184.16
MOP$399.96
List Price:  MOP$559.97
You save:  MOP$160.01
N$920.98
List Price:  N$1,289.45
You save:  N$368.46
C$1,839.04
List Price:  C$2,574.80
You save:  C$735.76
रु6,810.12
List Price:  रु9,534.71
You save:  रु2,724.59
S/186.41
List Price:  S/260.99
You save:  S/74.57
K202.74
List Price:  K283.85
You save:  K81.11
SAR187.78
List Price:  SAR262.91
You save:  SAR75.12
ZK1,383.10
List Price:  ZK1,936.45
You save:  ZK553.35
L239.36
List Price:  L335.12
You save:  L95.76
Kč1,209.95
List Price:  Kč1,694.03
You save:  Kč484.08
Ft19,835.61
List Price:  Ft27,771.44
You save:  Ft7,935.83
SEK kr553.09
List Price:  SEK kr774.38
You save:  SEK kr221.28
ARS$51,277.48
List Price:  ARS$71,792.58
You save:  ARS$20,515.09
Bs346.08
List Price:  Bs484.55
You save:  Bs138.46
COP$219,391.32
List Price:  COP$307,165.41
You save:  COP$87,774.08
₡25,377.51
List Price:  ₡35,530.54
You save:  ₡10,153.03
L1,269.45
List Price:  L1,777.33
You save:  L507.88
₲390,156.27
List Price:  ₲546,250
You save:  ₲156,093.73
$U2,225.52
List Price:  $U3,115.91
You save:  $U890.38
zł205.57
List Price:  zł287.82
You save:  zł82.24
Already have an account? Log In

Transcript

Hello and finance Hello What is this look statement okay and why is it know nothing about something going again and again okay I want it let me go here see, let me clear we understood this part Let me clear this see. So now let's see I have some piece of code we have written some piece of my code number one my code number line number two like this I have written some piece of code here, okay. Now, as I said my ignition is going to start line by line. So, like this painter to start, if there is no control flow statement, it will start, but do some thing I want. Okay, let's integrate execute these five statement atlases. 10 times okay my ignition will come like this okay my instead of going straight like this My ignition will come to this Okay, then I will execute this statement for 10 times in a loaf, okay.

Then time you do the statement again and again then go out. So if you want that kind of thing, we can use my looping statements. Okay, I will say, Lexi, whenever you are, you are in home, okay. So you do all the activities one by one to prepare food and you eat the food and you may study something Oh, you mean go to bed and sometimes decorating the room, you need to ship some books from one cell to another cell. That's a motto. You cannot take all the books in a single cell.

So maybe you have 15 number of books in one cell. So you will take pi books, keep it negative calm, take pi books, keep it like this. You're looking in your life for goal building and take same activity we're doing again and again and again. Same thing, insert these I may have five four lines of code is doing the same thing. And I can no big 10 times a couple times depending on my business environment for anybody who wants that kind of thing, we can go for the room. So normally this isn't law these four lines of code select the code only once you can go on the normal position.

But now these four line up or I can do it multiple times by my loop statements. And when I say loop statements, I have a do while I have a wife and also I have potluck segments so I'm we're going to discuss this three along so I can say one more equal policy, this points, different looping statements. Okay? Do while while for any cause until now. qualifying Yeah, yes. Perfect, perfect.

Okay, now let's see password understand what is do while and what is why we'll differentiate that to then go further. Okay, then we'll see what is foreign for it and unfortunately according to us, okay, so now let's see I will give you one basic scenario okay. There will define what is boilers but it will say both do the same activities, but in different context let's I'll give you one small scenario. We bought like he was waiting for this. Okay, so we get one one car to you. Okay, okay, maybe you can take the wallet or anything.

Okay. Now I used it before buying anything. Check if Have you have money in karate? Okay. Okay, let me write what should be happening on to see I'm doing okay. So Kyle benteke stealing her money and by the money over I said this line.

Okay, and one more scenario I'll say bye Are you do the shopping If you have money in your wallet okay this two thing I do, let's consider in my in my wallet Okay, I have only right now something like hyper diversity for example. Okay, only 500 USD. Now what happened? You went for something and that may cost around 900 Okay, so something are buying which cost 900 then EPC overpass arpit you buy it, then take your money again buy it. Okay, so in what's going to happen and one more thing that I said you before you buy you see either money or not. So now if I see some product is 900 something are going to buy within 150 and you have 500 USD Daniel by Norbert.

The you don't have money on your wallet which will cost 900 What do you have available but on so 500 but you cannot buy it okay. So that means you pastic how much available you have to check the condition if condition satisfied, then do it. So, so I can just more generically Canada Can I write eight hours? If conditions satisfied, then do it, this will swap even more money in record. So, if I just read the statement, if conditions are satisfied, then do it. Okay.

Kenny, Kenny, say this one pass do it. Then click the condition no password whatever past do read then check my condition. Okay, if still listen to this again, do it this bad. Okay, so now whenever I'm saying you have a valuable balance of hyper diversity, what do you want to buy something 900 and on this part You check the condition your balance is less than 900 that means you cannot buy anything hurt. But if you go on this area in a while loop you cannot buy any any anything. Am I correct?

Minus minus? Yes. Okay, so what I'm trying to say in a while Oh, we will pass check the condition, then we'll execute the statement if condition satisfied. Okay. And in do while what you do will pass integrate, then we will check condition satisfied then we'll continue again. So now on discuss what happens I have only 500 USD.

But if you see something I'm trying to buy which is 900 USD, so pass I'll buy it, then I will check. Okay, quite appropriate. I'm going to select Next. So for that, do I have balance or not? If you don't have, then we can revert past I can bite the legs. Take one more basic example.

Okay. Let's see you have found of around 3000 USD honor wallet okay now what is going to happen with this the certain University whatever you follow up so now I'm going to isolate first Niner Niner the fastest Iroquois this far okay? I have one product that I want to buy with 900 then I have 1000 and then we have with the 300 then again I have with 1000 and we have one with 1000 then sampled also yeah with so now I'm going to buy so see I have 3000 USD, okay. I checked balance 3000 which is greater than password I select is greater than 900 then what I did, so I simply went and I bought this one. Okay, then now for how much happened? So 3000 minus Niner.

Can I say no? I have only 2100 Okay, so then again I take away 2100 I have balance the order 100. Okay, I can by simply I go and pick it up. So then how much are you? Now I have 1100. So after this, I have 1100 so fast, I'm checking the condition, then I'm buying whatever I want.

Then I see like, okay, I haven't even under. So when I say I will live in under the under default of 300. Yes, I can buy. I'll go and simply, I'll buy this also. Okay, so now how much I have, then I have a 200. Okay, so now they're gonna say there is another 1% but I have 800 then I can pass I'm taking the condition.

Then I'm buying all the things, you know. But when I'm buying the same, same thing, I'm doing some state mitigation or I'm doing something. So when I say do while Eve I have heard of nine I have something with the 1000 okay then something we do 300 Okay, then I have something called 1000 okay and 500 okay many things, see, if I want to go past I will take it then as the governance those things. So, in the both things if you see this example of hybrid industry. So in the while loop, my statement may not integrate at all, whenever I have 500 and I have heard of I have something with Niner USD, I couldn't buy it. That means my statement is not going to do it at all.

But 2.0 while I'm exhibiting at least once, then I may not have not agreed. So, in Doyle saying, past time you execute your statement, then you check the condition. If condition matches, then we can loop it to execute again, while saying you pass check the condition, then take what happened to integral and still if it's satisfying you This so you can do it. For example, okay, let me show you one technical example here, we could do one, I have defined something called integer count. Let's see identity. And so now I say, do so now you can see, let's I'm just going to print this document.

I'm just going to make counts here. Okay, then I'm increasing my count one, count one, one. So it's not important as account loss loss, which will be equivalent to count equal to count plus one is nothing but mine was implemented operator to count equal to count plus one up on the right, simply you can write down so I'm increasing 10 to 1111 to 12 is time then then I'm going to check Hawaiian Okay, what condition I have, if till the time count less than 10 do it. If this is the master admin, so even do this, my count is 10 Okay, and my condition is Congress content okay let me write the syntax of do while first before going to here it will be like many people will be confused with the do while statement. So not to be confused okay. So I'm just writing the syntax here then you see a lot is not clear will not skip to entropy then if I do my statement a juice and press OK then check the condition till the time my condition satisfying will execute my look this is my do holster and when I say coil in the coil heart I have my coil segment which will be loops like this Okay.

So now while see I got while fast okay then insert is I will write my condition check okay then insert this registered. So that means this statement executed only when this condition in condition matches. So how we are going to do it? So now you can see if this is a do while statement. So now my count is 10 Okay, and I'm going to print the statements and I'm in taking the account value, insulin. Okay, so now let's see I actually got it, what's the output coming?

Let's see, I executed. So when I execute, if you go here let's debug it is showing 10 value on scurred say so again. So now EPC mechanism count less than 1010 is not less than 10 mechanism. Borstein. I have devoted my low once. Okay.

So past we do, then we'll check the statement to continue. Okay. If the same statement, if we will write on while statements. We'll see what happening. So I'm just covering this one. So let's see, I'm writing while.

Okay? Count less than 10. I'm just going to print the count. Okay? And I'm just initializing the round, equal 10. And also, I'm insert this increasing my count.

See, if I wrote these things, same kind of thing I'm doing, I do the condition check powers. In my condition satisfied and I wondering to see, I click on this part, nothing is going to come because my condition is fell already. My count is not less than 10. See, nothing, nothing is gone. So I didn't include anything. No statement code in the past.

I checked the statement then I do it. But in this case what happened first I executed, then I check my condition to see if I if you see how this eloping happens. Let's see, I kept my initial count is one I want to increase in my count is good. So when they come past what I'll do here, first I'll print one icon here my English status one year, my count value is one now, then do it what I will do, I will print my statement here first word secondary print, I will print one way to make count is one, then I'll come I'll increase that it means I had one value adding one which is going to be two then I'll check Okay, in the coin segment check to less than 10 Yes, mine will rest until again do the same thing. I'll come here I will bring what is over I will also count no boundaries to so the account Okay, then I can increase my to count two plus one, which is going to be three, then I check again, okay, three less than 10 is less than 10.

Again go again I print three here, I'll come here I increase one, which is going to be four like this may have been continuing, if I record this dogpile Now you will see this standard statement or these two statements what I have the intellect dude multiple times and each time we'll get one debug statements to see either executed. Let me execute. Let's see the lines see 123456789 everything we got it What can I say? Till the time my condition satisfied? I got it. Am I correct?

Only the difference between do wild and wild is that doing while past we check the condition then we start the education into well past We'll start the introduction then we'll start the condition check. Okay, so in the case of for counter to 10 in do while I got only one time and interesting happens, then my condition not met then I didn't go insert the loop, but in a while look past it is a condition condition not satisfied, I didn't come to inside. Okay, so this way we write my looking statements in the domain. So to highlight about we can execute the same thing again and again. Okay. Either same program I will try to write in the oil statement.

See, if I do it one thing do it one I'm just trying to execute only this must be supposed selected here. And I have a button called execute highlighted that means which I have highlighted, I like to do only that piece of code. I just integrate now in the whole segment. You see same kind of logo with Okay, that means I included that statement, which we have instead of Weissberg or insert that multiple times nine times eight okay. So, do let me know if any more questions on this or any questions on this day if you want the wisdom and so, like the difference between due Monday and while what I understand is like if you want to execute one condition at least one without checking the condition then we should use this do i right. Perfect.

Okay. Yeah, yes and I have another query is like, if we will make this integer value to final and then it will not work right. Let's see, how do you see now, we are we discussed what is my final part. Let's see if they try to use final here what is going to happen? So, they just happened count plus plus this is a final variable he will try to use what is happening here see basic elements cannot be modified again we already inserted it done yes perfect and it goes in lowercase yeah no emphasis No thank you. So, I hope everybody clear on this see while and do while on one line difference is that in do while past execute, then check the condition in a while past check the condition if satisfied then a good deal of time while my condition satisfying will continue the intuition that the point is the same and satisfying.

Yes. Same way, okay. So same way we are going to see in the let me copy this for you. Okay, I just put on I'll share with you all these few notes also Okay, very basic examples, okay, but to the specific levels we'll need in life always Okay. So now same way we have something called formal okay. And again I said I have two type of form of Okay.

What kind of follow via okay. So this is one follow up so whenever it is a follow okay what do you do the

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.