LOOPING STATEMENT IN QBASIC - Viral Tech updates

LOOPING STATEMENT IN QBASIC

Sometimes, tasks are repeated to finish a particular activity . For example, if we want all natural numbers less than 8 , we think and do the same task again and again
First we think of an even natural number more than 0 and less than 8.  The first one is 2 ; the next number ,more than 2 and less than 8 is 4; the next number ,more than 4and less than 8 is 6; the next number should be more than 6 and less than 8. Because no even number exists between 6 and 8, our repetition of task stop here.
So, instead of writing statement for all respective tasks , we can just write a single statement . Such a statement is called  a looping statement.
1. WHILE...WEND
2. DO...LOOP
3. FOR...NEXT
We shall study each of them in detail in this chapter.

WHILE...WEND STATEMENT
In a QBASIC program, it is written as :
WHILE condition
...
...
WEND
   The statement gives between WHILE and WEND form the loop body . The WHILE statement begins a loop which continues till the WHILE condition is true. This means, when the condition is true, the statement between WHILE and WEND are executed. When the condition becomes false, control is passed to the statement after WEEND

LET X =18
WHILE X>8
PRINT X
LET X=X-2
WEND
END
The output would be :
18,16,14,12,10

No comments