0% found this document useful (0 votes)
8 views3 pages

While Loop

The document contains a series of programming tasks that utilize while loops to perform various operations, including counting, printing even numbers, calculating sums, generating multiplication tables, and more. Each task is accompanied by pseudocode to illustrate the logic behind the implementation. The tasks also include user input validation and games, such as 'Guess the Number'.

Uploaded by

suwayne.84
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

While Loop

The document contains a series of programming tasks that utilize while loops to perform various operations, including counting, printing even numbers, calculating sums, generating multiplication tables, and more. Each task is accompanied by pseudocode to illustrate the logic behind the implementation. The tasks also include user input validation and games, such as 'Guess the Number'.

Uploaded by

suwayne.84
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

 Counting Loop

Write a program that uses a while loop to print the numbers from 1 to 10.

 Even Numbers
Write a program that prints all even numbers from 2 to 20 using a while loop.

 Sum of Numbers
Write a program that asks the user for a number N and then calculates the sum of numbers
from 1 to N using a while loop.

 Multiplication Table
Write a program that takes an input number and uses a while loop to print its multiplication
table up to 12.

 Reverse Countdown
Write a program that prints numbers from 10 down to 1, then prints "Liftoff!".

Counting Loop (1 to 10)


pseudocode
CopyEdit
SET i = 1
WHILE i <= 10 DO
DISPLAY i
i = i + 1
END WHILE

2. Even Numbers (2 to 20)


pseudocode
CopyEdit
SET i = 2
WHILE i <= 20 DO
DISPLAY i
i = i + 2
END WHILE

3. Sum of Numbers (1 to N)
pseudocode
CopyEdit
DISPLAY "Enter a number:"
INPUT N
SET sum = 0
SET i = 1
WHILE i <= N DO
sum = sum + i
i = i + 1
END WHILE
DISPLAY "Sum of numbers from 1 to", N, "is", sum
4. Multiplication Table
pseudocode
CopyEdit
DISPLAY "Enter a number:"
INPUT num
SET i = 1
WHILE i <= 12 DO
DISPLAY num, " x ", i, " = ", num * i
i = i + 1
END WHILE

5. Reverse Countdown (10 to 1)


pseudocode
CopyEdit
SET i = 10
WHILE i > 0 DO
DISPLAY i
i = i - 1
END WHILE
DISPLAY "Liftoff!"

6. User Input Validation (1-100)


pseudocode
CopyEdit
DISPLAY "Enter a number between 1 and 100:"
INPUT num
WHILE num < 1 OR num > 100 DO
DISPLAY "Invalid input! Enter again:"
INPUT num
END WHILE
DISPLAY "Valid number entered:", num

7. Guess the Number Game


pseudocode
CopyEdit
SET number = RANDOM(1, 50)
DISPLAY "Guess a number between 1 and 50:"
INPUT guess
WHILE guess ≠ number DO
IF guess > number THEN
DISPLAY "Too high! Try again:"
ELSE
DISPLAY "Too low! Try again:"
END IF
INPUT guess
END WHILE
DISPLAY "Congratulations! You guessed the number."
8. Factorial Calculation
pseudocode
CopyEdit
DISPLAY "Enter a number:"
INPUT N
SET factorial = 1
SET i = 1
WHILE i <= N DO
factorial = factorial * i
i = i + 1
END WHILE
DISPLAY "Factorial of", N, "is", factorial

9. Sum of Digits
pseudocode
CopyEdit
DISPLAY "Enter a number:"
INPUT num
SET sum = 0
WHILE num > 0 DO
SET digit = num MOD 10
sum = sum + digit
num = num DIV 10
END WHILE
DISPLAY "Sum of digits:", sum

10. Fibonacci Sequence (First 10 terms)


pseudocode
CopyEdit
SET a = 0
SET b = 1
SET count = 1
DISPLAY "Fibonacci Series:"
WHILE count <= 10 DO
DISPLAY a
SET next = a + b
SET a = b
SET b = next
count = count + 1
END WHILE

You might also like