0% found this document useful (0 votes)
38 views5 pages

IF THEN ELSE ENDIF Beginners

The document provides examples of pseudo code using different programming constructs like IF-THEN-ELSE, CASE-OF-OTHERWISE-ENDCASE, and FOR-TO-NEXT loops at beginner and intermediate levels. Examples include checking if a user is an adult, determining exam pass/fail status, selecting options in a menu, and iterating through numbers to calculate sums and print outputs.

Uploaded by

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

IF THEN ELSE ENDIF Beginners

The document provides examples of pseudo code using different programming constructs like IF-THEN-ELSE, CASE-OF-OTHERWISE-ENDCASE, and FOR-TO-NEXT loops at beginner and intermediate levels. Examples include checking if a user is an adult, determining exam pass/fail status, selecting options in a menu, and iterating through numbers to calculate sums and print outputs.

Uploaded by

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

IF THEN ELSE ENDIF beginners

In a simple pseudo code program, you want to check if a user's age is greater than or
equal to 18. If it is, the program should display "You are an adult," and if not, it should
display "You are a minor." Write the pseudo code for this program using
"IF...THEN...ELSE...ENDIF" statements.

IF
AGE > =18
THEN
OUTPUT “YOU ARE AN ADULT”
ELSE
OUTPUT “YOU ARE A MINOR”
END IF

IF THEN ELSE INTERMEDIATE

Write pseudo code that uses the IF...THEN...ELSE...ENDIF construct to


determine whether a student's exam score is passing or failing. The passing score is 60
or higher. If the score is passing, the program should output "Pass," otherwise, it should
output "Fail." Ensure that your pseudo code is properly structured and easy to
understand.

Your pseudo code should include the following elements:

 A variable to represent the student's exam score. \\


 An IF statement to check if the score is passing. //
 The appropriate output messages for passing and failing scores. \\
 The ENDIF to terminate the conditional block. \\

Feel free to provide the pseudo code for this problem.

DECLARE
STUDENT MARKS = X
IF
STUDENT MARKS >= 60
THEN
OUTPUT “PASS”
ELSE
OUTPUT “FAIL”
END IF

IF THEN ELSE END IF

"Write pseudo code that uses the IF...THEN...ELSE...ENDIF structure to determine whether a given
number is even or odd. Additionally, include a condition to check if the number is negative or
positive and provide different outputs based on these conditions. Explain the logic and flow of
your pseudo code."

IF
Number = “/ by 2”
OUTPUT
“EVEN”
ELSE
OUTPUT “ODD”
IF Number > 0
OUTPUT
“POSITIVE”
ELSE
OUTPUT
“NEGITIVE”
END IF
END IF

CASE OF … OTHERWISE … ENDCASE beginners LEVEL

Sure, here's a beginner-level pseudo code question involving the CASE OF... OTHERWISE...
ENDCASE construct:

**Question:**
In a simple pseudo code program, you are given a variable `userChoice` which can have values
'A', 'B', 'C', or 'D'. You need to implement a program that uses the CASE OF... OTHERWISE...
ENDCASE structure to perform different actions based on the value of `userChoice`. If the value
is 'A', the program should display "Option A selected." If the value is 'B', it should display
"Option B selected." If the value is 'C', it should display "Option C selected." If the value is 'D', it
should display "Option D selected." For any other value of `userChoice`, the program should
display "Invalid option." Write the pseudo code for this program using the CASE OF...
OTHERWISE... ENDCASE structure.

CASE OF USERS CHOICE

‘A‘ : OUTPUT “Option A selected ”


‘B’ : OUTPUT “Option B selected ”
‘C’ : OUTPUT “Option C selected ”
‘D' : OUTPUT “Option D selected ”

OTHERWISE
OUTPUT
“Invalid option”
END CASE

CASE OF … OTHERWISE … ENDCASE INTERMEDIATE LEVEL

Question: Write pseudo code that uses the CASE OF ... OTHERWISE ... ENDCASE
structure to determine the day of the week based on a numeric input (1 for Sunday, 2 for
Monday, and so on). Additionally, explain how you would handle cases where the input is not
within the valid range of 1 to 7.

CASE OF DAYS OF WEEK

‘1’ : OUTPUT “SUNDAY”


‘2’ : OUTPUT “MONDAY”
‘3’ : OUTPUT “TUESDAY”
‘4’ : OUTPUT “WEDNESDAY”
‘5’ : OUTPUT “THURSDAY”
‘6’ : OUTPUT “FRIDAY”
‘7’ : OUTPUT “SATURDAY”
OTHERWISE
OUTPUT “ INVALID ”
END CASE

FOR … TO … NEXT loops

"Imagine you're writing a simple program in pseudocode to count from 1 to 10 using a


FOR...TO...NEXT loop. Can you write the pseudocode for this loop, and explain how it works step
by step

FOR counter 1 to 10
output “count”
NEXT

Write a simple FOR...TO...NEXT loop in pseudo code that counts from 1 to 5 and displays the
current count on each iteration. Explain how this loop works step by step, and what the final
output will be.

FOR COUNTER 1 TO 5
OUTPUT
“COUNT + COUNTER”
NEXT
FOR … TO … NEXT loops INTERMEDIATE

Write a pseudo code snippet using a FOR...TO...NEXT loop to iterate through the numbers from 1
to 10 and print the square of each number. Explain how the loop works and what the expected
output will be.

FOR COUNTER 1 TO 10
OUTPUT
‘’The square of’’ +’’is’’ +(counter *counter)
NEXT
Write a pseudo code program that uses a FOR...TO...NEXT loop to calculate the sum of all even
numbers between 1 and 50 (inclusive). Explain each part of your pseudo code, including the
initialization, condition, and incrementation of the loop variable.

totalSum = 0 Initialize a variable to store the sum of even numbers

FOR number FROM 1 TO 50 DO

IF number % 2 == 0 THEN

totalSum = totalSum + number Add the even number to the total sum

END IF

NEXT number

OUTPUT "The sum of even numbers between 1 and 50 is: " + totalSum

You might also like