K
K
Kirill2021-11-01 16:14:52
C++ / C#
Kirill, 2021-11-01 16:14:52

How is While/Do while different from For?

Hello, I am a beginner programmer. C++ is the first language I started learning. Please tell me how While and Do While differ from For.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2021-11-01
Tritonov @tritonov01

The difference is only at the syntax level, just for is a special case of while:

int counter = start;
while(condition(counter)) {
   //...
   after(&counter);
}

against
for(int counter = start; condition(counter); after(&counter)) {
  //...
}

T
Tony, 2021-11-01
@AntonSazonov

for (;;) {}- loop with precondition
while () {}- loop with precondition. - loop with postcondition.
do {} while ()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question