Small Things Doesn’t Matter A Lot But They Matter Everything.
The title quote is quite frequently emphasised by my mentor Yogesh Bhatt at Masai School and inspiring from this I’m starting to write this…
Small Things Doesn’t Matter A Lot But They Matter Everything.
The title quote is quite frequently emphasised by my mentor Yogesh Bhatt at Masai School and inspiring from this I’m starting to write this series of blog in which will attempt explain the small basic but very significant concepts of the web development. As this will help me make my fundamental conceptual understanding crystal clear and hope it will do the same for my beloved readers. Henceforth this series will be known as Small Things Everything. So let’s begin.
Yesterday while in discussion with my friend we stumble upon easy looking but really fascinating question. What is the difference between For and While loop. Before we try to differentiate it lets try to understand the similarity and use of both. Both For-loop and While loop are use to repeat the piece of code inside the block. It takes some condition and run the loop till that condition is true. Once the condition is false the loop is completed and the code move to next block. This is also called as iteration.
Now lets try to understand the difference between for and while loop. On the basis of the three components of loop namely Variable, Condition and Increment/Decrement.
First on the basis of the variable. In For loop the variable for iteration is local, that is it is limited to that piece of code, while in While loop the variable that is used to iterate is global and can be access outside the iterative code. For example if we want to just iterate over an array best is For loop but when we have to use to increment the count variable from some else block of code, till some condition and use it some where else then best is While loop.
Second difference is on the basis of condition. If we know quite well about the limit of our loop the best option is For loop. In case of iteration over the array we know the size of array so we can use For loop. In case if the end condition is unknow or varying we can use the While loop. For example if we taking the input from scanner class and we don't know how many input we have to take, we can simply use while loop with condition has-next().
Thirdly on the basis for the incrementing/Decrementing condition. If the incrementing condition is constant then For loop is sufficient, but when the incrementing condition is varying depending on some another factors, For loop is have its limitation. In case of While loop we can modify our incrementing many time as much as possible by adding such condition. For example in for loop the increment can be one two or any fix number. In case of While loop while applying the two pointer technique(will cover it in future blog) on the array we can control the increment and decrement of this two pointers that is two variables separately at a same time.
Hope my attempt to explain the difference between For and While loop is helpful for you. Incase you have any suggestion or criticism feel free to let me know. I will back soon with another concept.
메타데이터
- post_id
- 717652adeaff
- slug
- small-things-doesnt-matter-a-lot-but-they-matter-everything-717652adeaff
- url
- https://medium.com/@kapilkhursade.210/small-things-doesnt-matter-a-lot-but-they-matter-everything-717652adeaff
- canonical_url
- https://medium.com/@kapilkhursade.210/small-things-doesnt-matter-a-lot-but-they-matter-everything-717652adeaff
- author_url
- https://medium.com/@kapilkhursade.210
- status
- ok
- fetched_at
- 2026-07-26 11:23:30