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.

What is the difference betwen fo r,while and do while

+11 votes
asked Dec 1, 2023 by Antonio Toma (220 points)

6 Answers

0 votes
answered Dec 4, 2023 by Mayank Aggarwal (140 points)

FOR loop runs till the given condition do not gets false, for loop can make changes in the counter variable(Increment or decrement). there are three parameters in for loop, initial value, condition, increment/decrement.
 

WHILE loop runs when the given condition is true.

+2 votes
answered Dec 5, 2023 by Peter Minarik (86,240 points)

Look at this article and click all types in green in the "Loop Type & Description" section to see the details.

+3 votes
answered Dec 16, 2023 by Muthulakshmi M (200 points)
if u know how many times u wanna do a iteration u can go with For loop

if u dont know the number of iterations u can go with While Loop

U dont know the number of iteration but ur code will perform the task once Even if the condition is false In Do while loop
0 votes
answered Dec 18, 2023 by Rohit Vaishnav (140 points)
while loop we use when compare between 2 condition true or false then we can use while loop.
0 votes
answered Dec 20, 2023 by Bihari Don (140 points)
WHILE -- FIRST CHECK CONDITION IF TRUE THEN REPEAT LOOP IF CONDITION FALSE THEN TERMINATE THE LOOP..

DO WHILE -- FIRST EXECUTE THE GIVEN CODE AND THEN CHECK CONDITION IF TRUE THEN REPEAT LOOP IF CONDITION FALSE THEN TERMINATE THE LOOP..

CONCLUSION -- WHILE LOOP FIRST CHECK CONDITION THEN EXECUTE AND DO WHILE LOOP AT LEAST EXECUTE ONE TIME RATHER THAN CONDITION IS TRUE OR FALSE.
0 votes
answered Dec 20, 2023 by Nitya Gol (140 points)

For loop is used when we know for how many times we need to run the loop. 

While loop and do while loop are used when we don't know how many times we need to run the loop. 

Do while loop is different rom while loop as do while loop will always run 1 time even if the condition is false but while loop will not run if the conditions is false. 

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...