Thursday, May 24, 2018

Fibonacci to 100

FOR LOOP and WHILE LOOP notes

 FOR LOOP



     FOR LOOP is a fixed repetition Loop, it will run the given number of times no matter how the body of FOR LOOP code changes the value of the variables. If you have a user defined constant, (for example, max_students or mortgage_rate) you can run the FOR LOOP for that many times. you can change the value of this type of user defined constant at the beginning of the program. Every year, you can change the value of max_students. The counter value increases or decreases depending upon the FOR LOOP minimum, maximum, incremented, or decremented values, automatically.

     No separate statement is made within the body of a FOR LOOP to increase or decrease the value of the counter. However, a separate variable is needed most of the time to run the FOR LOOP. A FOR LOOP can also start with a maximum value and decrease each time the body of the loop is executed.






WHILE LOOP

     WHILE LOOP can have various conditions and can be joined by AND, OR, NOT. The control enters the loop body only when the condition is met. If the condition is not met, the control moves to the statement following the end of the WHILE LOOP body. A statement within the WHILE LOOP changes the criteria and that actually moves the control out and to the statements that are following the end of the WHILE LOOP body.