Page 57 - 1
P. 57

6 Looping Statements
                            in QBASIc

Quick Glance                              For... Next with step
                                          While... Wend Statement
      For... Next Loop
      Nested-For... Next
      Do Until Statement

     I am                       Rizo,       Yes, Gizo.
     Gizo.                   how was       It was very
                             learning     interesting to
                            experience     learn about
                          about Q Basic
                             in the last     Q Basic
                          class? Want to   Yes, I want
                           learn more?
                                             to learn
                                               more.

For...Next Loop

It is very difficult to use multiple counters in large programs of QBASIC. To solve this

problem we have FOR...NEXT LOOP statements. This statement is used to repeat a program

segment in a loop in a controlled manner. It reduces the length of the program and makes it

easier.

Syntax

FOR <control variable>=<initial value>To<final value>

Statement

NEXT<control variable>

Example

REM Calculate sum of 5 numbers

CLS

SUM = 0

FOR AS = 1 to 5

                                                                                             57
   52   53   54   55   56   57   58   59   60   61   62