Discussion point: Question 4 (While loop or for loop)

Discussion point: Question 4 (While loop or for loop)

Which loop do you prefer to use in your programming - while or the for loop?

Response:

  • The general opinion is that it doesn't matter what you use as they both perform the same.
  • for loop is not scattered and initialization, condition, increment/decrements are in same place which is easy to understand
  • while loop is scattered where condition checking and increment/decrement are written in different places
  • usage of while and for loop depends on scenario, if you are waiting for an interrupt, or some input from external means
  • If the count is defined, designers use for loop and if there is a indefinite wait for some input while is used
A small test on the MSP432 board using Code Composer Studio, with a code written including for and while loop, gives a different view.

Post a Comment

0 Comments