We undergo sets of logical circuits while reaching to a conclusion, or a answer.
Those algorithms are quite similar to those of computer programming language, especially ‘if-else’, and ‘while’.
First, if-else loop, or ‘conditionals’ in easy language, is simply executing programmed action at certain conditions. For example, let’s think of a simple code that receives a natural number N, and returns True if N is even, and False if N is odd.
n = input(“Natural Number”)
if n % 2 == 0:
Our internal logical system works in same way. Nervous system and our perception work just like methods and operators such as ‘input(receive parameter)’ or ‘%(calculate remainder)’ from above, to collect and analyze information.
Another widely used loop is called ‘while’ loop. While loop executes something while certain statement is True. In other words, while loop does something until a change in conditional occurs.
For example, let’s say that Audrey is drinking tea in a teapot which is filled with 3 cups of tea, until teapot is empty. This situation can be described with while loop.
while (Pot is not empty):
Then, Audrey will drink 3 cups of tea, and stop. (drink – drink – drink (STOP))
And, maybe the most important algorithm in our logical system is ‘Break’, and ‘Continue’.
While loop not made properly, will lead to infinite loop, which is very inefficient and tiring thing to do.
So we have to judge conditions cleverly, and skip or stop at certain point.
Break, means to stop execution at certain condition, even during another loop.
Continue, means to skip current execution if certain conditional holds at current situation, even during another loop.
For example, Louis is playing a computer game with his laptop, and he promised himself to only play for a hour. But, if battery level is low, even before playing a hour, then he should turn off the computer. At this time, ‘break’ action occurs. 1 hour hasn’t passed yet(conditional is still true), but another, more important conditional(have enough battery) just became False. Then Break action will turn off the computer, and exit from the conditional(playing game).
Algorithms, such as several kinds of loops, are a path to find way to the answer. If you find the way to get to the answer, than your logical thinking, or computer languages such as C, python, or Java will drive you to the answer.
Algorithms, won’t directly give you the answer, but properly and neatly composed algorithms are key determinants for an efficient and fast way to get to the answer.
*def in codes means ‘define’, which defines a function and its characteristics.
ex) def [Function Name] (parameter):
=서원우(Korean Science Academy of KAIST, firstname.lastname@example.org)
2 thoughts on “Reply to Club Topic #2: Logical circuits; if-else, while, break/continue”
Love the example of me drinking tea. Haha.I also love how you said “Algorithms, won’t directly give you the answer, but properly and neatly composed algorithms are key determinants for an efficient and fast way to get to the answer.” It indeed is a very accurate description of algorithms. I am impressed with how specific and detailed your post is. It is very informative. Great work! 🙂
Whoa! I hate my programming class, but really this article makes me be interested in it. Nice work!