Computer Studies

What is a counter? Explain with reference to a program.

QBASIC: Conditional Statements

15 Likes

Answer

Counters are numeric variables that are used to keep a record of the number of times a process is repeated. A counter is initialised with a numeric value. and it increases by 1 as the process starts repeating.

For example, suppose we want to print our name five times on the screen, then we use counter.

Program:

CLS
C=1
LET N$ = "TOM"
START:
PRINT N$
C = C + 1
IF C <=5 THEN GOTO START:
END

Output:

TOM
TOM
TOM
TOM
TOM

Here C is the counter variable and keeps on incrementing till it reaches 5.

Answered By

7 Likes


Related Questions