Courses » SS3 » SS3 ICT » FOR-NEXT and WHILE-END Statements - SS3 ICT Lesson Note

FOR-NEXT and WHILE-END Statements - SS3 ICT Lesson Note

In BASIC programming, the FOR-NEXT and WHILE-END statements are used for controlling program flow and repeating actions.

 

FOR-NEXT Statement: This statement is used for creating loops with a specified start and end value. It allows you to execute a block of code a specific number of times.

basic Copy code

FOR i = 1 TO 10

    PRINT i

NEXT i

In this example, the code inside the loop will be executed 10 times, with the variable i taking values from 1 to 10.

 

WHILE-END Statement: The WHILE-END statement is used for creating loops based on a condition. It continues to execute the code inside the loop as long as the specified condition is true.

 

basic Copy code

x = 1

WHILE x <= 10

    PRINT x

    x = x + 1

WEND

Here, the code inside the loop will execute as long as x is less than or equal to 10.

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