12.05/12.06/12.07 - Assignments/Logic statements/Loops Flashcards
What does the following pseudocode do?
“INPUT Number”
It stores a value that is input in a variable with the identifier ‘Number’
Assigning a value
What does the following pseudocode do?
“NumOfGuesses <– 1”
Stores the value 1 in the variable with the identifier ‘NumOfGuesses’
Assigning a value
What does the following pseudocode do?
“NumOfGuesses <– NumOfGuesses+1”
It takes the value stored in ‘NumOfGuesses’, adds 1 to that value and then store the new value back into the variable ‘NumOfGuesses’
Updating a value
What does the following pseudocode do?
“Value2 <– Value1”
It takes the value in ‘Value1’ and copies it to ‘Value2’
Value in ‘Value1’ remains the same
Copying a value
How to swap the content of 2 variables?
We first need to store one of the values in another variable temporarily. Then we copy the content in the 2nd variable into the 1st variable. Then the content in the temporary variable is copied into the 2nd variable.
Why cant the content in 2 variables directly be swapped?
Beacuse the second value to be moved over written by the first value to be moved
What is a logic proposition?
A condition uses atleast one logic proposition. Logic propositions use the rational (comparison) operators
Conditions are either…
…True or False
How to form more complex conditions in pseudocode?
Using the logical operators
AND, OR and NOT
What are the 3 types of loops?
- REPEAT…UNTIL
- FOR…NEXT
- WHILE…ENDWHILE
Which type of loops should be used instead of REPEAT…UNTIL if the loop should not be executed at all certain points?
WHILE…ENDWHILE
Which loop type is suitable to use if the number of repetitions is known?
FOR…NEXT
Which loop type is suitable to use if the statement inside might never be executed?
WHILE…ENDWHILE