Conditional Loops WHILE and REPEAT UNTIL :
1. Find the Sum of Positive Numbers (Using While Loop)
Problem Statement:
Write a pseudocode program that keeps asking the user to enter positive numbers and calculates the sum. If the
user enters a negative number, stop the loop and display the sum.
Pseudocode:
BEGIN
sum ← 0
INPUT num
WHILE num >= 0 DO
sum ← sum + num
INPUT num
ENDWHILE
PRINT "Sum of positive numbers:", sum
END
2. Find the Largest Number (Using While Loop)
Problem Statement:
Write a pseudocode program that repeatedly asks the user to enter numbers. The loop stops when the user enters
-1, and the program prints the largest number entered.
Pseudocode:
BEGIN
largest ← -99999
INPUT num
WHILE num != -1 DO
IF num > largest THEN
largest ← num
ENDIF
INPUT num
ENDWHILE
PRINT "Largest number entered:", largest
END
3. Password Validation (Using Repeat-Until Loop)
Problem Statement:
Write a pseudocode program that asks the user to enter a password. If the password is incorrect, ask again. If the
password is correct, print "Access Granted."
Pseudocode:
BEGIN
correctPassword ← "admin123"
REPEAT
INPUT userPassword
IF userPassword != correctPassword THEN
PRINT "Incorrect password. Try again."
ENDIF
UNTIL userPassword = correctPassword
PRINT "Access Granted"
END
4. Count Even and Odd Numbers (Using While Loop)
Problem Statement:
Write a pseudocode program that takes numbers from the user until 0 is entered. The program counts how
many even and odd numbers were entered.
Pseudocode:
BEGIN
evenCount ← 0
oddCount ← 0
INPUT num
WHILE num != 0 DO
IF num MOD 2 = 0 THEN
evenCount ← evenCount + 1
ELSE
oddCount ← oddCount + 1
ENDIF
INPUT num
ENDWHILE
PRINT "Total even numbers:", evenCount
PRINT "Total odd numbers:", oddCount
END
5. Find the First Number Greater than 100 (Using Repeat-Until Loop)
Problem Statement:
Write a pseudocode program that asks the user for numbers. If a number greater than 100 is entered, stop asking
and print the number.
Pseudocode:
BEGIN
REPEAT
INPUT num
IF num <= 100 THEN
PRINT "Number too small, try again."
ENDIF
UNTIL num > 100
PRINT "You entered:", num
END
6. Guess the Secret Number (Using While Loop)
Problem Statement:
Write a pseudocode program that allows the user to guess a secret number until they guess correctly. If the
guess is too high or too low, give hints.
Pseudocode:
BEGIN
secret ← 37
INPUT guess
WHILE guess != secret DO
IF guess < secret THEN
PRINT "Too low, try again."
ELSE
PRINT "Too high, try again."
ENDIF
INPUT guess
ENDWHILE
PRINT "Congratulations! You guessed it!"
END
7. ATM Withdrawal Simulation (Using Repeat-Until Loop)
Problem Statement:
Write a pseudocode program that simulates an ATM withdrawal. The user can only withdraw if they have
enough balance. The loop continues until a valid withdrawal amount is entered.
Pseudocode:
BEGIN
balance ← 5000
REPEAT
PRINT "Enter withdrawal amount:"
INPUT amount
IF amount > balance THEN
PRINT "Insufficient balance. Try again."
ELSE
balance ← balance - amount
ENDIF
UNTIL amount <= balance
PRINT "Withdrawal successful. Remaining balance:", balance
END
8. Print Multiplication Table (Using While Loop)
Problem Statement:
Write a pseudocode program that prints the multiplication table of a given number using a while loop.
Pseudocode:
BEGIN
INPUT num
i ← 1
WHILE i <= 10 DO
PRINT num, " x ", i, " = ", num * i
i ← i + 1
ENDWHILE
END
Practice Tasks:
Questions Based on While Loop:
1. Temperature Monitor:
Write a pseudocode program that keeps asking the user for the current temperature. If the temperature is
above 40°C, display a warning message. If it is below 10°C, display a cold alert. Stop when the user
enters 999.
2. Number Categorizer:
Write a pseudocode program that takes n numbers as input and counts how many are positive, negative,
and zero. Stop the loop when the user enters -999.
3. ATM Withdrawal:
Write a pseudocode program that allows a user to withdraw money from an ATM. The program should
keep asking for an amount until the user enters a value within their balance. If the user tries to withdraw
more than their balance, display an error message.
4. Guess the Secret Number:
Write a pseudocode program that allows the user to guess a secret number (e.g., 42). If the guess is too
high, display "Too High"; if too low, display "Too Low". The loop should continue until the correct
number is guessed.
5. Login Authentication:
Write a pseudocode program that asks a user to enter a username and password. If the details are
incorrect, the system should display an error and prompt the user again. The loop continues until the
user enters the correct credentials.
Questions Based on Repeat-Until Loop:
6. User Input Validation:
Write a pseudocode program that asks the user to enter a positive number. If the user enters a negative
number, display an error message and ask again. The loop continues until a positive number is entered.
7. Find the First Even Number:
Write a pseudocode program that asks the user to enter numbers. If the number is odd, display a message
and ask for another number. Stop when the user enters an even number.
8. Password Retry System:
Write a pseudocode program that asks the user to enter a password. If the password is incorrect, display
an error message and ask again. Stop when the correct password is entered.
9. Sum of Numbers Until Zero is Entered:
Write a pseudocode program that keeps adding numbers entered by the user. Stop the loop when the user
enters zero, then display the total sum.
10. Shopping Cart System:
Write a pseudocode program that allows a user to add prices to a cart. If a price entered is negative,
display an error. The loop continues until the user enters 0, then display the total bill.