Friday, August 9

WHILE-WEND statement

The WHILE-WEND statement executes a series of statements in a loop as long as given condition is true.
Syntax
LN WHILE expression
.
.
.
[loop statements]
.
.
.
WEND
Where ,
LN       : Line Number
expression     : valid BASIC expression
loop statement  : Series of statement which are to be repeated
Points to Remember

  • If expression is true, loop statements are executed until the WEND statement is encountered.
  • If expression not true execution starts with the statement following the WEND statement.

     Example
1. Write a BASIC program to find the sum of first N numbers using WHILE-WEND loop.

CS 7.9 Display on the screen for WHILE-WEND statement.

Ok
LIST
5     REM Learning use of the WHILE....WEND statement
10   INPUT "ENTER VALUE OF N:" ; N
20   LET SUM = 0 : LET CNT = 0
30  WHILE (CNT<N)
40  CNT = CNT+1
50  SUM = SUM+CNT
60 WEND
70 PRINT " The sum of number from 1 to 100 "; N; is  : "; SUM 
80 END
Ok
RUN
ENTER VALUE OF N: : ? 100
The sum of number 1 to 100 is : 5050 
Ok


No comments:

Post a Comment