Comments that are too Pseudocode.
Comments that are too Pseudocode.
Have you ever looked a piece of code and wondered if it could be in a universal programming language that anyone could understand - even non-programmers?
Well Good News!! There is Pseudocode, which uses an easy to read and understand syntax to do just that and I have an example of some Pseudocode of a list of books that when iterated through will tell you whether or not you have read the book or not below.
Pseudocode
Task 2: Reading List
ARRAY = 'Dragon and Ceremony - From a Wandmaker's Perspective by Ichimei Tsukushi': Read (TRUE),
'Sweetness & Lightning Vol 8 by Gido Amagakure': Read (TRUE),
'Kuma Kuma Kuma Bear by Kumanano Vol 16': Unread (FALSE);
FOR NUMBER Less Than the Length of ARRAY:
IF Item NUMBER in ARRAY = Read THEN:
PRINT 'You have already read ' Item NUMBER in ARRAY;
ELSE:
PRINT 'You still need to read ' Item NUMBER in ARRAY;
Alternatives to Pseudocode
Now if Pseudocode isn't your thing because you can't program working software with it, then there are comments which you can use to add notes to program explaining what each line of code is doing. In JavaScript a for a line to be a comment it must start with a double slash (//) and each programming language will have its own way of commenting.
As an example, I have included function 4 from 'Four functions and seven years ago' blog post, now with comments which you'll know because they all be in green.
JavaScript Code
//Run function TemperatureCheck passing temperature variable as an argument
function TemperatureCheck(temperature){
//If temperature is less than 0 then:
if (temperature < 0) {
//Output to the console 'Stay Inside'
console.log('Stay Inside');
}
//Else, if temperature is less than 30 then:
else if (temperature < 30) {
//Output to the console 'Wear a coat and hat'
console.log('Wear a coat and hat');
}
//Else, if temperature is less than 50 then:
else if(temperature < 50){
//Output to the console 'Wear a coat'
console.log('Wear a coat');
}
//Else then:
else{
//Output to the console 'Pants and vest are fine'
console.log('Pants and vest are fine');
}
}
//Set num1 as a constant with a value of 35
const num1 = 35;
//Set num2 as a constant with a value of 25
const num2 = 25;
//Set num3 as a constant with a value of -5
const num3 = -5;
//Set num4 as a constant with a value of 55
const num4 = 55;
//Call TemperatureCheck function with num1 passed as a temperature argument
TemperatureCheck(num1);
//Call TemperatureCheck function with num2 passed as a temperature argument
TemperatureCheck(num2);
//Call TemperatureCheck function with num3 passed as a temperature argument
TemperatureCheck(num3);
//Call TemperatureCheck function with num4 passed as a temperature argument
TemperatureCheck(num4);