1K Blog Marathon: Day 9
Today I’m not feeling well,🤒😷🤧🤮💊💉 and I’m sorry for my blog post today. I am very ill, and at the moment my head is hurting. But I don’t want to skip a day in my 1K Blogging Marathon, so here is one of my treasured article that I wrote last year. This topic revolves around my first programming language, Visual Basic.
IF block without the need of END IF closing
Did you know that you can evaluate an IF condition with only one-line and without the need for END IF? This is an IF block (we also have IF-END IF, IF-ELSE-END IF, IF-ELSEIF- END IF, and IF-ELSEIF-ELSE-END IF)
Here is the format: IF <condition> then <action>
strColor = “blue” strResponse = “” IF strColor = “red” then strResponse = “The color is red!”
‘This will set strResponse to “” (empty) since the condition is FALSE.
A ternary operator is an inline IF block that evaluates a condition then return either of the two output separated by comma in ONE SINGLE LINE!
Format: IF(<condition>,<value if TRUE>, <value if FALSE>)
strAnimal = “dog” strResponse = IF (strAnimal=”dog”,”The animal is a dog!”,”The animal is not a dog.”)
‘This will set strResponse to “The animal is dog!”, since the condition (IF strAnimal=“dog”) is TRUE
This is very useful if you only have 2 exact action from a True or False condition. It would not only save a line of code, it will also make your prof or superior yell “Nayswan!”
When dealing with numbers, the division process gives us different output depending on the symbol we use. You are familiar with the SLASH “/” symbol. This is the very basic division symbol used. But did you know that there are 2 other symbol that you can use aside from this so-called forward slash? I’ll list it down for you.
1. Forward Slash (“/”) – the basic division symbol. This will give you a quotient with a whole number and the decimal places (if applicable)
intQuotient = 100/3
This will give you 33.3333333……
2. Back Slash (“\”) – this process outputs the Whole Number of the quotient – that is, the decimal places (if applicable) is removed.
intQuotient = 100\3
This will give you 33
3. Modulo (“Mod”) – this is the magic word when you want to get the remainder of the dividend and divisor. This is helpful when you are coding Roman Numerals or Currency Denomination (Programming Competition’s favorite problem!)
intRemainder = 100 mod 3
This will give you 1
So, next time you deal with Divison, you have 3 options to chose from: getting the RAW, the ROUNDED OFF, or the REMAINING! ^_^
“And that’s one blog, stay hungry!”
“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”― Martin Fowler