Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.
Login
Login
OnlineGDB Q&A
Questions
Unanswered
Tags
Ask a Question
Ask a Question
difference between for loop and while loop
+8
votes
asked
3 days
ago
by
Swaliha S
(
210
points)
Please
log in
or register to answer this question.
2 Answers
0
votes
answered
2 days
ago
by
Mrunaal Earla
(
150
points)
for loop will be used when we know how many number of iterations we needed to do and
while is used when we don't know how many iterations do we require to do
and also
in some cases we can use both for / while loop anyone would be great.
Please
log in
or register to add a comment.
0
votes
answered
1 day
ago
by
pugazh
(
140
points)
Feature
for Loop
while Loop
Best used when
Number of iterations is known
Number of iterations is not known in advance
Structure
Initialization, condition, and update are written together
Initialization and update are usually written separately
Readability
More compact for counting loops
More flexible for condition-based loops
Common use
Traversing arrays, repeating a fixed number of times
Reading input until a condition changes, waiting for an event
Please
log in
or register to add a comment.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...