Courses » SS3 » SS3 ICT » Sample Programs - SS3 ICT Lesson Note

Sample Programs - SS3 ICT Lesson Note

1. Using FOR-NEXT Statement:

basic Copy code

REM Program to print numbers from 1 to 10 using FOR-NEXT

FOR i = 1 TO 10

    PRINT i

NEXT i

 

2. Using WHILE-END Statement:

basic Copy code

REM Program to print numbers from 1 to 10 using WHILE-END

x = 1

WHILE x <= 10

    PRINT x

    x = x + 1

WEND

 

3. Storing Data in a Vector (Array):

basic Copy code

REM Declare an array of 10 integers

DIM numbers(10)

 

REM Assign values to the array

FOR i = 1 TO 10

    numbers(i) = i

NEXT i

 

4. Calculating the Average of a One-Dimensional Array:

basic Copy code

REM Calculate the average of an array with 100 numeric values

DIM data(100)

total = 0

REM Assign values to the array (assume values are already present)

FOR i = 1 TO 100

    total = total + data(i)

NEXT i

average = total / 100

PRINT "Average: "; average

These examples demonstrate the basic usage of FOR-NEXT and WHILE-END statements for loops, as well as storing data in an array and calculating the average of values in the array. 

 

Recommended: Questions and Answers on Basic Programing III for SS3 ICT
Please share this, thanks:

Add a Comment

Notice: Posting irresponsibily can get your account banned!

No responses