Loop Statement
Loop statements are used to execute one or more statements multiple times. These are The FOR & NEXT statements. The form of the FOR - NEXT statement is whereK—must be a variable.m1 – initial value of Km2– final value which K can assume.m3– size of the step by which the value of K will be changed.m1, m2, m3 may be constants, variables or expressions. Their values may be negative, positive or zero. K is called the counter variable or the index of the FOR- NEXT statement.Eg: 14 FOR L= 1 TO 10 STEP 2Here K=L, m1=1, m2=10, m3=2. The counter variable L can assume the values 1, 3, 5, 7,9.If the step is 1, the specification STEP m3 may be omitted. The form of the FOR-TO statement becomeseg: 30 FOR K=1 TO 50Whenever a FOR-TO statement is used, there must be a corresponding NEXT statement. Its function is to increase the value of the counter variable by the step size. The format of this statement is where k -- must be the variable used in the FOR-TO statement as the counter variable. The NEXT statement cannot be used independently and must follow the FOR-TO statement. We denote the loop as
|
Last modified: Wednesday, 18 January 2012, 10:52 PM