Loop Statement

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
    loop
    where
    K—must be a variable.
    m1 – initial value of K
    m2– 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 2
    Here 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 becomes
    loop
    eg:
    30 FOR K=1 TO 50
    Whenever 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
     loop
    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
loop

Last modified: Wednesday, 18 January 2012, 10:52 PM