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
€46.41
List Price:  €64.99
You save:  €18.57
£39.85
List Price:  £55.80
You save:  £15.94
CA$68.38
List Price:  CA$95.74
You save:  CA$27.36
A$75.69
List Price:  A$105.97
You save:  A$30.28
S$67.65
List Price:  S$94.71
You save:  S$27.06
HK$390.96
List Price:  HK$547.38
You save:  HK$156.41
CHF 45.35
List Price:  CHF 63.50
You save:  CHF 18.14
NOK kr542.95
List Price:  NOK kr760.18
You save:  NOK kr217.22
DKK kr346.22
List Price:  DKK kr484.74
You save:  DKK kr138.51
NZ$83.20
List Price:  NZ$116.49
You save:  NZ$33.28
د.إ183.60
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,484.79
List Price:  ৳7,679.15
You save:  ৳2,194.35
₹4,174.22
List Price:  ₹5,844.24
You save:  ₹1,670.02
RM236.85
List Price:  RM331.61
You save:  RM94.76
₦61,737.65
List Price:  ₦86,437.65
You save:  ₦24,700
₨13,903.63
List Price:  ₨19,466.20
You save:  ₨5,562.56
฿1,842.69
List Price:  ฿2,579.91
You save:  ฿737.22
₺1,612.90
List Price:  ₺2,258.19
You save:  ₺645.29
B$253.75
List Price:  B$355.28
You save:  B$101.52
R922.13
List Price:  R1,291.06
You save:  R368.92
Лв90.85
List Price:  Лв127.20
You save:  Лв36.34
₩67,969.88
List Price:  ₩95,163.27
You save:  ₩27,193.39
₪185.94
List Price:  ₪260.34
You save:  ₪74.39
₱2,861.35
List Price:  ₱4,006.12
You save:  ₱1,144.77
¥7,722.34
List Price:  ¥10,811.89
You save:  ¥3,089.55
MX$843.21
List Price:  MX$1,180.56
You save:  MX$337.35
QR182.28
List Price:  QR255.22
You save:  QR72.93
P678.57
List Price:  P950.05
You save:  P271.48
KSh6,648.67
List Price:  KSh9,308.67
You save:  KSh2,660
E£2,385.52
List Price:  E£3,339.92
You save:  E£954.40
ብር2,869.28
List Price:  ብር4,017.22
You save:  ብር1,147.94
Kz41,825.96
List Price:  Kz58,559.69
You save:  Kz16,733.73
CLP$46,485.20
List Price:  CLP$65,083
You save:  CLP$18,597.80
CN¥354.33
List Price:  CN¥496.09
You save:  CN¥141.76
RD$2,899.21
List Price:  RD$4,059.13
You save:  RD$1,159.91
DA6,716.85
List Price:  DA9,404.13
You save:  DA2,687.28
FJ$112.23
List Price:  FJ$157.14
You save:  FJ$44.90
Q388.45
List Price:  Q543.86
You save:  Q155.41
GY$10,455.72
List Price:  GY$14,638.84
You save:  GY$4,183.12
ISK kr6,977.10
List Price:  ISK kr9,768.50
You save:  ISK kr2,791.40
DH500.96
List Price:  DH701.39
You save:  DH200.42
L885.56
List Price:  L1,239.86
You save:  L354.29
ден2,861.59
List Price:  ден4,006.46
You save:  ден1,144.86
MOP$402.29
List Price:  MOP$563.24
You save:  MOP$160.94
N$920.44
List Price:  N$1,288.69
You save:  N$368.25
C$1,839.55
List Price:  C$2,575.52
You save:  C$735.96
रु6,679.37
List Price:  रु9,351.66
You save:  रु2,672.28
S/186.27
List Price:  S/260.79
You save:  S/74.52
K193.32
List Price:  K270.67
You save:  K77.34
SAR187.48
List Price:  SAR262.50
You save:  SAR75.01
ZK1,358.11
List Price:  ZK1,901.47
You save:  ZK543.35
L231.01
List Price:  L323.43
You save:  L92.42
Kč1,161.35
List Price:  Kč1,625.98
You save:  Kč464.63
Ft18,056.25
List Price:  Ft25,280.20
You save:  Ft7,223.94
SEK kr542.25
List Price:  SEK kr759.20
You save:  SEK kr216.94
ARS$44,003.90
List Price:  ARS$61,608.98
You save:  ARS$17,605.08
Bs345.36
List Price:  Bs483.53
You save:  Bs138.17
COP$195,270.45
List Price:  COP$273,394.26
You save:  COP$78,123.80
₡25,568.20
List Price:  ₡35,797.53
You save:  ₡10,229.32
L1,234.61
List Price:  L1,728.55
You save:  L493.94
₲373,712.67
List Price:  ₲523,227.64
You save:  ₲149,514.97
$U1,909.55
List Price:  $U2,673.53
You save:  $U763.97
zł200.30
List Price:  zł280.44
You save:  zł80.13
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.