Which of the following statements can be used for looping in BASIC?
Correct Answer: A
FOR ... NEXT loop is specifically designed for counting iterations. It allows you to specify a starting value, an ending value, and an increment (or decrement) for the loop counter.basic
FOR counter = start TO end [STEP step]
' Code to execute
NEXT counterbasic
FOR i = 1 TO 5
PRINT i
NEXT i
This code will print the numbers 1 through 5. The loop starts with i equal to 1 and increments i by 1 until it reaches 5.
IF ... THEN statement is used for conditional execution, not for looping. It allows you to execute a block of code only if a certain condition is true.basic
IF x > 10 THEN
PRINT "x is greater than 10"
END IFGO TO statement can be used to jump to a specific line in the code, which can create a form of looping if used carefully. However, it is not structured or recommended for creating loops because it can lead to "spaghetti code," making programs hard to read and maintain.basic
10 PRINT "Hello"
20 GO TO 10FOR ... NEXT.GO SUB statement is used to call a subroutine, which is a block of code that can be executed. While you can return to the main program after executing a subroutine, it does not inherently create a loop.basic
GO SUB 100
...
100 PRINT "This is a subroutine"
RETURNFOR ... NEXT loop is the correct and structured way to implement looping in BASIC.IF ... THEN is for conditional execution, not looping.GO TO can create loops but is not a recommended practice due to potential code readability issues.GO SUB is for calling subroutines and does not create loops.