For Loop




Examples:
1) Program to print Even Numbers:
2) Program to find the sum of natural numbers from 1 to 1000.
When you run the program, the output will be:
Here, the variable sum is initialized to 0. Then, in each iteration of for loop, variable sum is assigned sum + i and the value of i is increased until i is greater than 1000. For better visualization,
Nested For Loop:

Example 1: Program to create a pattern
Here is a program to create the above pattern using nested loops.
Example 2: Program to create a pattern
Here is a program to create the above pattern using nested loops.
Example 3: Program to create a pattern
Problems:
1) WAP to print Odd Numbers.
2) WAP to draw the below patterm.
3) WAP to draw the below pattern.
4) WAP to draw the below pattern.
Last updated
Was this helpful?