Aryan Khandelwal
10 pages
Aryan Khandelwal
10 pages
173
/ 10
CodeWithNishchal
LOGIC BUILDING WITH LOOPS
(BEFORE STARTING DSA)
Phase 1 – While Loop
Phase 2 – do while loop
Phase 3 – For Loop
Phase 4 – Nested loop Logic
Phase 5 – Break / Continue logic
Phase 6 – Mathematical Series
Phase 7 – Mixed Logical Loop Problems
Phase 8 – Star Pattern Printing
🎯
Goal: Master loops, iteration, and dry-run thinking.
Topics covered: while, do-while, for, break, continue,mathematical series.
Target Questions: 125+
Phase 1 : While Loop
1. Print all numbers from 1 to 10 using a loop.
2. Print numbers from 10 down to 1 in reverse order.
3. Print all even numbers between 1 and 100.
4. Print all odd numbers between 1 and 100.
5. Print the multiplication table of a given number from n × 1 to n × 10.
6. Calculate and print the sum of the first n natural numbers.
7. Calculate the sum of all even numbers from 1 up to n.
8. Calculate the sum of all odd numbers from 1 up to n.
9. Calculate and print the factorial of a given number.
10. Find and print the product of all digits of a given number.
11. Count and print the total number of digits in a given number.
12. Reverse the given number and print the reversed value.
13. Check whether the given number is a palindrome.
14. Find and print the sum of digits of the given number.
15. Check whether the given number is an Armstrong number.
16. Check whether the given number is a Perfect number.
17. Print all prime numbers between 1 and 100.
18. Check whether the given number is a prime number.
19. Print the Fibonacci series up to n terms.
20. Find and print the sum of the Fibonacci series up to n terms.
21. Print the square of each number from 1 to n.
22. Print the cube of each number from 1 to n.
23. Print all numbers between a and b that are divisible by 7.
CodeWithNishchal
24. Print all factors of the given number.
25. Find and print the sum of all factors of the given number.
26. Find the HCF (Highest Common Factor) of two given numbers.
27. Find the LCM (Least Common Multiple) of two given numbers.
28. Find the smallest digit in the given number.
29. Find the largest digit in the given number.
Phase 2 : do - While Loop
1. Print all numbers from 1 to 10.
2. Print the multiplication table of a given number.
3. Keep taking numbers from the user until 0 is entered, then print the sum of all
entered numbers.
4. Keep taking numbers from the user until 0 is entered, then print the largest number
among all inputs.
5. Count and print the number of digits in the given number.
6. Reverse the given number and print the reversed value.
7. Check whether the given number is a palindrome.
8. Check whether the given number is an Armstrong number.
9. Calculate and print the factorial of the given number.
10. Print the Fibonacci series up to the required number of terms.
11. Find the HCF (Highest Common Factor) of the given numbers.
12. Create a menu-driven program that allows the user to choose and perform different
operations.
13. Keep taking numbers from the user until a negative number is entered, then count
how many positive numbers were entered.
14. Find and print the sum of digits of the given number.
15. Calculate and print the sum of even digits and the sum of odd digits of the given
number separately.
Phase 3 : For Loop
1. Print all numbers from 1 to 10.
2. Print numbers from 10 down to 1 in reverse order.
3. Print all even numbers between 1 and 100.
4. Print all odd numbers between 1 and 100.
5. Print the multiplication table of a given number.
6. Calculate and print the factorial of a given number.
7. Calculate and print the factorial of every number from 1 to n.
8. Print all prime numbers between 1 and 100.
9. Check whether the given number is a prime number.
10. Print the Fibonacci series up to the required number of terms.
CodeWithNishchal
11. Find and print the sum of the Fibonacci series.
12. Print all factors of the given number.
13. Find and print the sum of all factors of the given number.
14. Find the HCF (Highest Common Factor) of the given numbers.
15. Find the LCM (Least Common Multiple) of the given numbers.
16. Print the square of each number from 1 to n.
17. Print the cube of each number from 1 to n.
18. Print all numbers between a and b that are divisible by 7.
19. Find and print the sum of the first n natural numbers.
20. Find and print the sum of all even numbers from 1 up to n.
21. Find and print the sum of all odd numbers from 1 up to n.
Phase 4 : Nested Loop Logic
1. Print the multiplication tables for all numbers from 1 to 10.
2. Print all possible pairs (i, j) where both i and j range from 1 to n.
3. For every number from 1 to n, count and print the total number of its factors.
4. Print all prime numbers up to n using nested loop checking.
5. Print the Fibonacci pattern row by row, where each row prints the next Fibonacci
numbers
6. Generate and print a number triangle pattern using nested loops.
7. Print a matrix, then calculate and display the sum of each row and the sum of
each column.
8. Print all Pythagorean triplets whose values are less than or equal to n.
Phase 5 : Break / Continue Logic
1. Print numbers from 1 to 100, and stop the loop as soon as a number divisible by
17 is encountered.
2. Print numbers from 1 to 100, but skip all numbers that are divisible by 5 and
continue printing the rest.
3. Take 5 numbers as input, skip any number that is 0 using continue, and
calculate the sum of the remaining numbers.
4. Search for a specific number in a list of inputs, and terminate the loop immediately
when the number is found.
5. Keep taking numbers from the user and print them until a negative number
appears, then stop the loop.
6. Skip all odd numbers and print only the even numbers.
7. Continuously add numbers in a loop and stop the loop when the sum becomes
greater than 100
/ 10
End of Document
173