It’s like I am having a hard time to grasp with a decision box or a do-while box. But mostly with a decision box and there is something I can’t grasp apart from the instructions box and the input box which I understand very well and it is that what function does it play in the computer the decision box or the do-while box that makes it unique apart from other boxes.
Like what kind of decision is a decision box with the pseudocode like:
Enter x
If x<0
Else y= x^2 + yx
Else end y=x
What kind of logic does it make?
#Pseudocode and algorithms
1 messages · Page 1 of 1 (latest)
It's a bit difficult to understand what you're trying to say. You're trying to understand the differences between the if-else and do while and how are they used? If so, hopefully my answer will help you
if-else`
if-else statements, or conditionals, executes a specific block of code depending on certain conditions.
Ex. In this example, we have a variable age containing the age of the user. We want to know if the user is old enough (18) to perfom_action.
IF age > 18
write "You are an adult, you can perfom this action"
ELSE THEN
write "You are not old enough to perform this action!"
END IF
do while
The do while is looping mechanism and a variant of the while loop. It executes a block of instructions and repeats it if a given condition is true or exits the loop.
Ex. In this example, we want the user to enter his password and then validate if the entered_password matches password. In case the password doesn't match, we want to ask the user to enter it again until the right one is entered.
password = "hello123"
DO
ENTER entered_password
WHILE entered_password != password
As you can see, both the if-else and do while affects the control flow of your program and rely on conditions but they will affect the flow differently. You want to use if-else statements when you have decisions to make that will execute different instructions. You want to use do while when you have to execute and repeat some instructions depending on a given condition.