# Best Digital Marketing Company in Hyderabad for Loops factor

We don't need to know how many items are in this array. It could be hundreds it could be thousands. But here we just loop through until we get the value we're looking for. Now while loop you know it's probably not the best solution for this particular situation but it definitely does work. So let's clear that we'll look for a digital marketing company in Hyderabad run it again and we can see that we find Joe and Joe happens to be the last one if we have a bunch more names.

Jane Amy Ashley Billy it doesn't matter how many in here we just loop through until we find the one we're looking for the right which just happens to be this number three we want to look for Ashley instead. We can do that for an online marketing company. Right. And this loop would actually make a lot more sense if instead of just doing you know always checking if it's true we can check. Well, it is the index less than the number of names in the array. A name start length. If we can select that out we'll be up to see names at length because I didn't quite catch. Try again. Seven right. One two three four five six seven.

Factors:

So instead of just kind of hard-coding in value, we just loop through good index is less than seven at this time starting at zero. That's how we can go until it's less than seven. We loop through until we find the name we're looking for. We cancel out the one we are looking for and then we break out of that loop. So if we take a look after the loop digital marketing company in Hyderabad runs what is the value of the index. Let's see what it actually does that check out. Yep, so we looped. And then we stopped the loop immediately as soon as we got to what we were looking for. And if we look for Chris instead for example clear run it again. Well, Chris is in index position.

So we didn't even bother to iterate over the rest of the names they just immediately stopped broke out of the loop and it works exactly as we saw in terms of the switch statement right we just break out of the switch statement and if we wanted to kind of abstract this into more of a function we could do something like.

Function name Luper takes an array then move the while loop into the function and indent it. Of course and then instead we can do here let index while the index is less than our length for a digital marketing company in Hyderabad our index or index and then we can invoke name Luper pass it in the names array we're run. So has the same functionality.

Verdict:

And just for practice if we want it to tell it hey we're looking for a certain username maybe we can then pass that in as well. All right. So hey function. I want to be able to reuse this name Luper. So look for names and look for this name inside this array that I'm telling you to look for it. There you go.  That next type of loop I would like to take a look at it is called a do while statement.

So do that while and do while it's actually very similar to a just a regular while loop with the exception that the code inside the condition will run even if it evaluates to false the first time. In other words, the code always executes at least once before the condition is checked. So it looks like this and does it this way. So you give it a DO statement you give it some code to execute it so statement while condition makes so.

So what this looks like it would be something like this say will do let should run only once equal let's say even if this is false we always want this to kind of execute through one time anyway. So if you want something to run at least once if not more than once and then you would say do console for the best digital marketing company in Hyderabad log looping and then should run only once. Equals false. For example. So even if this were true in the first case it's going to run once and then re-initialize it defaults while should run only once so the code is kind of backward. If you look at it that way compared to like a regular wild statement.

Conclusion:

So if we try to run this it's run it's looping and you know what. I'm not going to invoke this function. I will just raise that code. Ok, so I see that it is working just fine and even though it's checking to do this while should only run it should only open only once is true. Right, that's what this is saying but it kind of executes the code before it even gets there. So again you do this if you want something to always run at least once if not more than that.

And we could say let index equal zero in here we can say index plus equals. And again we can do an if statement in here if an index is equal to then we'll switch this left from false from true to false. It's so clear that it will run its K: loop times and then we switch the flag to false and it stops running. So let's lets we read this for a digital marketing company in Hyderabad example a little bit. Let's get some kind of user input going here and we can basically loop until the user tells us to exit. So we can say let condition don't really need to instantiate it. We just want it to exist. And we can say do it will prompt the user enters a queue to exit and it will assign this to a constant for every loop through concentric user input equals prompt press Q to exit.