Skip to main content

How Does While Loop Work?

I think that everybody knows what while means, right?

Imagine you want to do something for a 'while' :)
You're gonna need to repeat that thing for a number of times; limited or unlimited. For example, if you wanted to do something from your daily life like drinking water 7 times each day you're going to do a task (i.e process) for seven times and you're going to decrease that number each time you drink water. Before you start drinking, the number of times would be seven. So,  a condition to check to stop drinking would be great. Like when the number of times is less than seven -> continue doing this process (drinking water) and increasing the number of times you have drank  by one. Once the number of times reaches seven -> stop this process.

Hope that helped clear the picture even if it was a little bit.

Comments

Popular posts from this blog

Stack vs. Queue

Stack is like a pile of  books placed on top of each other. We can add new books to the top and can remove them from only the top because stacks are LIFO which means last-in, first-out. Queues on the other hand are the opposite, which is FIFO meaning first-in, first-out. So adding an element to the queue will be the same but removing will happen to the first element not the last one. An example of a queue would be the wait line in front of any kind of service we see around us like the bus station or the shops,....etc.

Middlewares

Middlewares in Javascript are functions that come in the middle of the request-response cycle. They have access to both the request and the response object as well as the next middleware function to be executed; usually called next(). Popular examples on middleware include: body-parser, cors, session, cookie-seesion and cookie-parser.