FOR-NEXT Loop

 FOR...NEXT loop

This is the most common loop for a known number of repetitions. It uses a counter variable to track the number of cycles and stops when the counter reaches a specified limit.
Syntax
FOR counter = start TO end [STEP increment]
    ' Code block to be executed
NEXT counter
Use code with caution.
  • counter: A variable that is automatically incremented or decremented with each loop cycle.
  • start: The initial value of the counter.
  • end: The final value of the counter, which, when exceeded, terminates the loop.
  • STEP: An optional keyword to specify the increment or decrement value. If omitted, the step is assumed to be 1. 
Example:

1. Program to display " First TEN natural number using FOR-NEXT loop. 
2. Program to display " First TEN ODD number using FOR-NEXT loop. 

3. Program to display " First TEN EVEN number using FOR-NEXT loop.
 

4.  Program to display " Multiplication table (constant number) using FOR - NEXT loop.

5.  Program to display " Multiplication table (variable number) using FOR - NEXT loop.





No comments:

Post a Comment