Difference between revisions of "CSharp to Pseudo Code"
(→C#) |
(→Assigning a value) |
||
Line 1: | Line 1: | ||
==Assigning a value== | ==Assigning a value== | ||
'←' is to assign a value to a variable, essentially just like '=' in C#. | '←' is to assign a value to a variable, essentially just like '=' in C#. | ||
+ | |||
+ | ==IF== | ||
+ | In pseudo code an if statement has several parts, the command word 'IF' followed by a condition, followed by the word 'THEN'. | ||
+ | |||
+ | For example: | ||
+ | |||
+ | IF factorfound = FALSE THEN | ||
+ | |||
+ | The code to run for the if will be between the 'THEN' and the 'ENDIF. | ||
+ | |||
+ | ===C#=== | ||
+ | <syntaxhighlight lang=csharp> | ||
+ | if (factorfound == false) | ||
+ | { | ||
+ | ......... | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==If Else== | ||
+ | The same as above, however the code to run for the if will be between the 'THEN' and the 'ELSE'. The code between the 'ELSE' and the 'ENDIF' will be run when the condition is false. | ||
+ | |||
+ | For example: | ||
+ | |||
+ | IF factorfound = FALSE THEN | ||
+ | ......... | ||
+ | ELSE | ||
+ | ......... | ||
+ | ENDIF | ||
+ | |||
+ | The code to run for the if will be between the 'THEN' and the 'ENDIF. | ||
+ | |||
+ | ===C#=== | ||
+ | <syntaxhighlight lang=csharp> | ||
+ | if (factorfound == false) | ||
+ | { | ||
+ | ......... | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | ......... | ||
+ | } | ||
+ | </syntaxhighlight> | ||
==While Loop== | ==While Loop== |
Revision as of 13:24, 18 January 2019
Assigning a value
'←' is to assign a value to a variable, essentially just like '=' in C#.
IF
In pseudo code an if statement has several parts, the command word 'IF' followed by a condition, followed by the word 'THEN'.
For example:
IF factorfound = FALSE THEN
The code to run for the if will be between the 'THEN' and the 'ENDIF.
C#
if (factorfound == false)
{
.........
}
If Else
The same as above, however the code to run for the if will be between the 'THEN' and the 'ELSE'. The code between the 'ELSE' and the 'ENDIF' will be run when the condition is false.
For example:
IF factorfound = FALSE THEN ......... ELSE ......... ENDIF
The code to run for the if will be between the 'THEN' and the 'ENDIF.
C#
if (factorfound == false)
{
.........
}
else
{
.........
}
While Loop
The command words used in the exam questions is:
WHILE (Condition) .................... ENDWHILE
Condition will be something which equates to either true or false. Some examples of the conditions are:
WHILE (root * root) < Number
or:
WHILE (factorfound = false)
So the condition is always contained within the round brackets.
C#
Remember to check if something is equal in C# is '=='.
Remember 'Greater than or Equal' or Less than or Equal' is '>=' or '<='.
while (factorfound == false)
{
............
}