0% found this document useful (0 votes)
175 views8 pages

BCA 1st Year QBASIC Looping Statement Prakash Dayal

The document discusses different types of looping statements in QBASIC programming language: - For Next loop allows executing a set of statements repeatedly for a given number of times using syntax like FOR counter = start TO end [STEP]. - While loop executes statements until a condition is satisfied using syntax like WHILE <condition>. - Do loop performs instructions if a comparison is true and has four syntax variations like DO...WHILE, DO...LOOP WHILE, DO UNTIL, and DO...LOOP UNTIL. Examples are given to print natural numbers from 1 to 10 using different loops.

Uploaded by

mc andrian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views8 pages

BCA 1st Year QBASIC Looping Statement Prakash Dayal

The document discusses different types of looping statements in QBASIC programming language: - For Next loop allows executing a set of statements repeatedly for a given number of times using syntax like FOR counter = start TO end [STEP]. - While loop executes statements until a condition is satisfied using syntax like WHILE <condition>. - Do loop performs instructions if a comparison is true and has four syntax variations like DO...WHILE, DO...LOOP WHILE, DO UNTIL, and DO...LOOP UNTIL. Examples are given to print natural numbers from 1 to 10 using different loops.

Uploaded by

mc andrian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Looping Statement

In QBASIC
loop is a sequence of instructions that is repeated until
a certain condition is reached.

loops are used to execute a set of statements repeatedly until a


particular condition is satisfied,

QBasic programming language provides the following types


of loops to handle looping requirements.
• For Next loop
• while loop
• Do loop
Loops allows a specified group of statements to be executed a certain number of
times while certain condition is true. 
For Next Loop is used to execute the set of statements repeatedly for a given number of times.

For Loop’s syntax 


FOR counter = start TO end [STEP]
    [Statement Block]
NEXT counter

Example

FOR i = 1 TO 4 step 2
PRINT “Hello world!"
NEXT i
Write a program to print the natural numbers from 1 to 10.

Cls
FOR x=1 to 10
Print x
Next x
End

Write a program to print even numbers from 1 to 20

CLS
FOR I = 2 to 20 step 2
PRINT I
NEXT I
END
WHILE ... WEND loop
In a WHILE ... WEND loop, if the condition is True, all statements are executed until WEND
keyword is encountered. If the condition is false, the loop is exited and the control jumps to
very next statement after WEND keyword.

While Loop’s syntax


WHILE <condition>
{Code}
WEND

Example

i=10
While i>5
Print “hello”
i=i-1
Wend
DO ... LOOP
It is another type of looping statement in QBASIC. Sometime it is also called
DO WHILE LOOP. In this loop, the instructions within the loop are performed if
the comparison is true. We can use this loop by 4 different methods. Syntax
are

Do loop’s Syntax

Syntex 1
Syntex 2
DO … WHILE
DO
{STATEMENTS}
{STATEMENTS}
LOOP
LOOP WHILE [CONDITION]

Syntex 3
Syntex 4
DO UNTIL
{STATEMENTS} DO
LOOP {STATEMENTS}
LOOP UNTIL
Example

WAP to print the natural numbers from 1 to 10

CLS
n=1
DO
PRINT n;
n=n+1
Loop While n<=10
End

WAP to print the numbers from 20 to 1 in descending order

CLS
n=20
DO
PRINT n;
n= n- 1
LOOP UNTIL n<1
END
END

You might also like