Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 104 - 2505_CoreGPT(Podar)_Flipbook_C7
P. 104

    4.  Update Statement: This modifies the counter variable to either increase or decrease its

                          value, ensuring the loop progresses or  terminates as required.  The default  increment is
                          usually 1, but it can be adjusted by the user.
                      For…NEXT Statement

                      The FOR...NEXT statement is used to run a code a fixed number of times. To manage this kind
                      of loop, we create a variable that tracks how many times the loop will run. Generally, this variable
                      is called a count control variable. The basic syntax of the FOR...NEXT statement is as follows:

                      FOR counter = startNumber TO endNumber
                             Statements to repeat
                             Increase or decrease the counter variable
                      END
                      Where,

                          the counter is a variable that keeps count of the number of times the instructions inside the
                          loop have been executed.
                          the startNumber is the starting number of value of the loop.
                          the endNumber is the total number of times the loop must run.
                      Let us see a program to understand the concept of FOR...NEXT statement.

                                                             Printing numbers 1 to 15

                      This program prints the numbers from 1 to 15 in order. The concept of increasing the value of
                      a variable is used in programming very often. So, most of the programming languages have a
                      simpler and easier way to do this. In the preceding example, the variable i contains a value that
                      increases by 1 each time the loop runs.

                    102     Premium Edition-VII

| 99 100 101 102 103 104 105 106 107 108 109 |