Computer Science, asked by jayendra4371, 2 months ago

What will be the output for the
following program - FOR I = 1
TO 2 STEP 0.25 PRINT I NEXT I​

Answers

Answered by gunjan089
1

Explanation:

While programming, you may want to repeat the execution of a certain set of statements multiple times. This can be done using loops. A loop is used to repeat the execution of a group of statements many times. Statements that enable us to create loops are known as looping statements. We will learn the following looping statements in QBASIC.

FOR….. NEXT

DO…..LOOP

Using FOR…NEXT Statement for Looping

The FOR…NEXT statement is used when you want a group of statements to be executed a specific number of times.

The general form of the FOR…NEXT statement is given below.

FOR counter = initial value to final value [STEP value]

The loop body comprising a set of statements to be executed

NEXT counter

The statements written between FOR and NEXT form the body of the loop.

In the above-mentioned FOR…NEXT statement,

counter is a numeric variable that controls the loop and hence is also called the control or the index variable. Its value changes every time the loop body gets executed.

step value is the value by which the counter variable is incremented or decremented every time the loop body is executed. It can be a positive or a negative value, but it cannot be zero. The step value is optional. In case it is omitted, the counter variable is increased by one every time the loop is executed.

Consider the following example based on FOR…NEXT loop.

In this example,

Control variable: A

Initial value of control variable: 1

Final value of control variable: 3

Step value: 1

Attachments:
Similar questions