Computer Science, asked by Schooliscool5610, 1 year ago

Difference between 3 loops in c and where to use them

Answers

Answered by bhatttsawtii
1

Major difference between for and while loop is at pragmatic level because under the hood, both loops are all the same conditional goto; therefore the choice between while and for is arbitrary, based on which seems clearer. Both for and while loops are entry controlled loops that means test condition is checked for truth while entering into the loop's body.

The for is usually appropriate for loops in which the initialization and increment are single statements and logically related, since it is more compact than while and it keeps the loop control statements together in one place.

The for loop seems most appropriate when number of iteration are known in advance, for example, counting array elements. But, there could be many complex problems where number of iterations depend upon a certain condition and can't be predicated beforehand, in those situation programmers usually prefer to use while loop. The following table lists differences between for and while loop.


Anonymous: Can We Convert For Loop Into While Loop
Anonymous: And Vice Versa
bhatttsawtii: yes
Anonymous: Thanks
Anonymous: But Can you Tell Me How?
Anonymous: If You Want You Can Have My Whatsapp no....9001522002
Answered by Anonymous
0
Major difference between for and whileloop is at pragmatic level because under the hood, both loops are all the same conditional goto; therefore the choice between while and for is arbitrary, based on which seems clearer. Both for and whileloops are entry controlled loops that means test condition is checked for truth while entering into the loop's body.

The for is usually appropriate for loops in which the initialization and increment are single statements and logically related, since it is more compact than while and it keeps the loop control statements together in one place.

The for loop seems most appropriate when number of iteration are known in advance, for example, counting array elements. But, there could be many complex problems where number of iterations depend upon a certain condition and can't be predicated beforehand, in those situation programmers usually prefer to use while loop. The following table lists differences between forand while loop.

Similar questions