Single FOR Loop Programs with Working Principle
1. Print numbers from 5 to 15
Code:
For I = 5 to 15
Print I
Next I
End
Working Principle: - I runs from 5 to 15. - Prints: 5, 6, 7, … 15.
2. Print first 10 even numbers
Code:
For I = 2 to 20 step 2
Print I
Next I
End
Working Principle: - Step value is 2. - Prints: 2, 4, 6, … 20.
3. Print squares of numbers from 1 to 5
Code:
For I = 1 to 5
Let S = I * I
Print S
Next I
End
Working Principle: - Prints: 1, 4, 9, 16, 25.
4. Print multiplication table of 9
Code:
For I = 1 to 10
Let P = 9 * I
Print P
Next I
End
Working Principle: - Prints multiples of 9 up to 90.
5. Print reverse numbers from 20 to 10
Code:
For I = 20 to 10 step -1
Print I
Next I
End
Working Principle: - Prints: 20, 19, 18, … 10.
6. Print odd numbers from 1 to 19
Code:
For I = 1 to 19 step 2
Print I
Next I
End
Working Principle: - Prints: 1, 3, 5, … 19.
7. Print cubes of numbers from 1 to 6
Code:
For I = 1 to 6
Let C = I * I * I
Print C
Next I
End
Working Principle: - Prints: 1, 8, 27, 64, 125, 216.
8. Print series 5, 10, 15, … 50
Code:
For I = 5 to 50 step 5
Print I
Next I
End
Working Principle: - Prints multiples of 5 up to 50.
9. Print numbers from 30 to 40
Code:
For I = 30 to 40
Print I
Next I
End
Working Principle: - Prints: 30, 31, 32, … 40.
10. Sum of numbers from 1 to 10
Code:
Let S = 0
For I = 1 to 10
S = S + I
Next I
Print S
End
Working Principle: - Final sum printed: 55.
11. First 10 multiples of 3
Code:
For I = 1 to 10
Let M = 3 * I
Print M
Next I
End
Working Principle: - Prints: 3, 6, 9, … 30.
12. Reverse even numbers from 20 to 2
Code:
For I = 20 to 2 step -2
Print I
Next I
End
Working Principle: - Prints: 20, 18, 16, … 2.
13. Multiplication table of 7
Code:
For I = 1 to 10
Let P = 7 * I
Print P
Next I
End
Working Principle: - Prints: 7, 14, 21, … 70.
14. Print letters A to Z
Code:
For I = 65 to 90
Print Chr(I)
Next I
End
Working Principle: - Prints: A to Z.
15. Print 5 stars in one line
Code:
For I = 1 to 5
Print "*";
Next I
End
Working Principle: - Prints: *****
Double FOR Loop Programs
1. 5×5 Star Square
Code:
For I = 1 to 5
For J = 1 to 5
Print "*";
Next J
Print
Next I
End
Output:
*****
*****
*****
*****
*****
Working Principle: Outer loop prints 5 rows, inner loop prints 5 stars per row.
2. 4×4 Number Box (1 2 3 4)
Code:
For I = 1 to 4
For J = 1 to 4
Print J;
Next J
Print
Next I
End
Output:
1234
1234
1234
1234
Working Principle: Inner loop prints 1 to 4 each row.
3. Print 1 to 5 in 5 Rows
Code:
For I = 1 to 5
For J = 1 to 5
Print J;
Next J
Print
Next I
End
Output:
12345
12345
12345
12345
12345
Working Principle: Same row repeated 5 times.
4. Right Triangle of Stars
Code:
For I = 1 to 5
For J = 1 to I
Print "*";
Next J
Print
Next I
End
Output:
*
**
***
****
*****
Working Principle: Inner loop prints stars equal to row number.
5. Right Triangle of Numbers
Code:
For I = 1 to 5
For J = 1 to I
Print J;
Next J
Print
Next I
End
Output:
1
12
123
1234
1235
Working Principle: Inner loop prints 1 to I.
6. Row Number Repeated Pattern
Code:
For I = 1 to 5
For J = 1 to I
Print I;
Next J
Print
Next I
End
Output:
1
22
333
4444
55555
Working Principle: Prints I repeated I times.
7. Multiplication Table (1–5)
Code:
For I = 1 to 5
For J = 1 to 5
Print I * J;
Next J
Print
Next I
End
Output: Multiplication grid 1 to 5.
8. Alphabet Rows (A–E)
Code:
For I = 1 to 5
For J = 65 to 69
Print Chr(J);
Next J
Print
Next I
End
Output:
ABCDE
ABCDE
ABCDE
ABCDE
ABCDE
Working Principle: ASCII 65–69 print A–E.
9. Reverse Triangle of Stars
Code:
For I = 5 to 1 step -1
For J = 1 to I
Print "*";
Next J
Print
Next I
End
Output:
*****
****
***
**
*
Working Principle: Row decreases each iteration.
10. Reverse Number Rows
Code:
For I = 1 to 5
For J = 5 to 1 step -1
Print J;
Next J
Print
Next I
End
Output:
54321
54321
54321
54321
54321
Working Principle: Inner loop counts downwards.
11. Hollow 5×5 Star Square
Code:
For I = 1 to 5
For J = 1 to 5
If I = 1 Or I = 5 Or J = 1 Or J = 5 Then
Print "*";
Else
Print " ";
End If
Next J
Print
Next I
End
Output:
*****
* *
* *
* *
*****
Working Principle: Prints stars only at borders.
12. 3×7 Star Rectangle
Code:
For I = 1 to 3
For J = 1 to 7
Print "*";
Next J
Print
Next I
End
Output:
*******
*******
*******
Working Principle: Outer loop controls rows, inner loop prints 7 stars.
13. Print All Pairs (I, J)
Code:
For I = 1 to 3
For J = 1 to 3
Print I;" ";J
Next J
Next I
End
Output:
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Working Principle: Each I pairs with every J.
14. Number Pyramid (Up & Down)
Code:
For I = 1 to 5
For J = 1 to I
Print J;
Next J
Print
Next I
For I = 4 to 1 step -1
For J = 1 to I
Print J;
Next J
Print
Next I
End
Output:
1
12
123
1234
12345
1234
123
12
1
Working Principle: First loop increases, second decreases.
15. Tables of 2 to 5
Code:
For I = 2 to 5
For J = 1 to 10
Print I * J;
Next J
Print
Next I
End
Output: Shows 2×1 to 5×10.
Working Principle: Row = table number.
16. Even Number Rows
Code:
For I = 1 to 5
For J = 1 to 5
Print J*2;
Next J
Print
Next I
End
Output:
2 4 6 8 10
2 4 6 8 10
2 4 6 8 10
2 4 6 8 10
2 4 6 8 10
Working Principle: Inner loop prints even numbers.
17. Square Table Pattern
Code:
For I = 1 to 5
For J = 1 to 5
Print J*J;
Next J
Print
Next I
End
Output:
1 4 9 16 25
(repeated 5 rows)
Working Principle: Inner loop prints J².
18. Alphabet Triangle
Code:
For I = 1 to 5
For J = 1 to I
Print Chr(64+I);
Next J
Print
Next I
End
Output:
A
BB
CCC
DDDD
EEEEE
Working Principle: Prints character equal to row number.
19. Checkerboard Pattern (1 & 0)
Code:
For I = 1 to 5
For J = 1 to 5
If (I+J) Mod 2 = 0 Then
Print "1";
Else
Print "0";
End If
Next J
Print
Next I
End
Output:
10101
01010
10101
01010
10101
Working Principle: Even sum prints 1, odd prints 0.
20. Row Sum Table
Code:
For I = 1 to 5
Let S = 0
For J = 1 to 5
S = S + J
Next J
Print S
Next I
End
Output:
15
15
15
15
15
Working Principle: Each row sums 1–5.
21. Pattern 11*
Code:
For I = 1 to 4
For J = 1 to 5
If J Mod 2 = 1 Then
Print "*";
Else
Print "1";
End If
Next J
Print
Next I
End
Output:
*1*1*
*1*1*
*1*1*
*1*1*
Working Principle: Odd column = star, even = 1.
22. Column-wise Counting
Code:
For I = 1 to 5
For J = 0 to 4
Print I + J*5;
Next J
Print
Next I
End
Output:
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25
Working Principle: J*5 jumps to next column.
23. Hollow Pyramid Outline
Code:
For I = 1 to 5
For J = 1 to I
If J = 1 Or J = I Or I = 5 Then
Print "*";
Else
Print " ";
End If
Next J
Print
Next I
End
Output:
*
**
* *
* *
*****
Working Principle: Borders printed, middle empty.
24. Sliding Numbers Pattern
Code:
For I = 1 to 5
For J = I to I+4
Print J;
Next J
Print
Next I
End
Output:
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
5 6 7 8 9
Working Principle: Each row starts one number higher.
25. Product Table (I×J)
Code:
For I = 1 to 5
For J = 1 to 5
Print I * J;
Next J
Print
Next I
End
Output:
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 16 16 20
5 10 15 20 25
Working Principle: Row number I multiplied by column number J.
Code for Formula-Based Questions
1. Square of first 10 numbers
For N = 1 to 10
Let S = N * N
Print S
Next N
End
2. Cube of first 10 numbers
For N = 1 to 10
Let C = N * N * N
Print C
Next N
End
3. Triangular numbers Tₙ = n(n+1)/2
For N = 1 to 10
Let T = N*(N+1)/2
Print T
Next N
End
4. Pentagonal numbers Pₙ = n(3n−1)/2
For N = 1 to 10
Let P = N*(3*N - 1)/2
Print P
Next N
End
5. Even numbers Eₙ = 2n
For N = 1 to 10
Let E = 2 * N
Print E
Next N
End
6. Odd numbers Oₙ = 2n−1
For N = 1 to 10
Let O = 2*N - 1
Print O
Next N
End
7. (n² + n)/2
For N = 1 to 10
Let V = (N*N + N)/2
Print V
Next N
End
8. Sum of first n even numbers = n(n+1)
For N = 1 to 10
Let S = N*(N+1)
Print S
Next N
End
9. Sum of first n odd numbers = n²
For N = 1 to 10
Let S = N*N
Print S
Next N
End
10. Perimeter of rectangle P = 2(L + B)
Input B
For L = 1 to 10
Let P = 2*(L + B)
Print P
Next L
End
11. Area of rectangle A = L × B
Input B
For L = 1 to 10
Let A = L * B
Print A
Next L
End
12. Simple Interest SI = (P × R × T)/100
Input P, R, T
Let SI = (P * R * T)/100
Print SI
End
13. Compound Amount A = P(1 + R/100)^T
Input P, R, T
Let A = P * (1 + R/100)^T
Print A
End
14. Fibonacci series
Let A = 0
Let B = 1
Print A, B
For I = 3 to 10
Let C = A + B
Print C
Let A = B
Let B = C
Next I
End
15. Multiplication table T = n × i
Input N
For I = 1 to 10
Print N * I
Next I
End
16. Squares of even numbers (2n)²
For N = 1 to 10
Let Even = 2*N
Let S = Even * Even
Print S
Next N
End
17. Decreasing AP Tₙ = a − (n−1)d
Input A, D
For N = 1 to 10
Let T = A - (N-1)*D
Print T
Next N
End
18. GP Tₙ = arⁿ⁻ ¹
Input A, R
For N = 1 to 10
Let T = A * (R^(N-1))
Print T
Next N
End
19. Fahrenheit to Celsius C = 5(F−32)/9
For F = 0 to 100 step 10
Let C = 5*(F-32)/9
Print C
Next F
End
20. Km to meters m = km × 1000
For KM = 1 to 10
Let M = KM * 1000
Print M
Next KM
End