Behold! The power of functions

Image for post
Image for post
A guide for beginners of any background to start writing codes

Thus far, we feel pretty good about our little program that greets people as they come into a chat room. We limit the guest count to 5 and we stop anyone who is under age from entering the room. Finally, we customized our greeting message and displayed a different message based on the age of a guest.

What if, I like this idea of displaying customized messages so much that I wish to use it on multiple occasions? By that I mean not just greeting people as they enter the room. …


Image for post
Image for post
A guide for beginners of any background to start writing codes

In the previous article, we briefly touched on the subject of decision making. It is used for solving dilemmas and performing a set of tasks on a decision made in programming.

In this article, we are going to address two particular scenarios that are common when using “if” statements along with some tricks.

What if I don’t have a case for “else”?

It’s perfectly normal for an “if” statement to have no “else”. The reason is simple, we sometimes do not wish to perform some actions when the decision was ruled against a dilemma.

An example can be given from our famous chat room scenario. What if, instead of displaying a message to anyone who’s under 18 and simply just ignore them? Like an arrogant butler who only greets people who made it into the chat room. …


We want you! To make a decision.

Image for post
Image for post
A guide for beginners of any background to start writing codes

In our previous articles, we learned about how to master a variety of loops. Giving you the ability to control the flow of a process by repeating a group of tasks. How about adding one more tool to your inventory and gain the ability to help computers make a decision?

Why do I want to learn “if” statement at all?

The short answer is, to solve dilemmas and perform tasks based on the decision within a program. Like always, the “why” can be explained from an example.

Let’s continue from our chat room example, which greets people by their name as they come in and limits the number of guests to just under 5. Let’s append one more interesting condition to this example, say forbid anyone who’s under 18 from entering the room? …


What we do to stop loops from getting out of control

Image for post
Image for post
A guide for beginners of any background to start writing codes

Thus far, we know a loop without a constraint will run forever. Therefore, we need a way to stop the execution of a loop.

In addition to adding a counter and checking against its value within a while loop, we have something else that provides more control.

Introducing — the “For” loops

In our scenario mentioned in the previous article, we want our program to loop for only 5 times so that exactly 5 people can be allowed to enter the room.

On one hand, we certainly can use “while” loop to accomplish this task, but on the other hand, with this clear defined restraint on the condition, we can adopt the use of “For” loop. …


Image for post
Image for post

We briefly talked about how to use the “while” loop in our previous example to repeatedly ask people’s name when they enter the chat room. Today let’s take a closer look at some of the tricks we can pull off when using the loop.

Keep it simple and short

If you remember from a few articles back, we’ve mentioned that programmers like to keep their codes short. We introduced an idea called chaining the actions (instructions), and we can do the same here with the “while” loops as well. Consider the following.

<?php    While ($names=readline('What is your name: '))    {        echo 'Good morning master '.$names;

If only there are ways to repeat some tasks in the programming world…

Image for post
Image for post
A guide for beginners of any background to start writing codes

Previously, we learned about what variables are, why they exist, how and why we use them. Let’s switch gears and take a look at this new instruction from the programming family — Loops.

So we have built this little program that greets whoever enters the system, but it stops once someone puts in his/her name.

What if we are building this program for a chat room and we want to greet everyone who comes into the room? …


In the previous article, we talked about why, when and how to use a variable with examples. In this session, we will dive into more details of using a variable and learn some tricks with practical examples.

Image for post
Image for post
A guide for beginners of any background to start writing codes

Variable initialization

In our previous example, we declared a variable called “names” and assigned a value “Tom” to it. This process is called value assignment. It takes two lines of code to do the declaration and the assignment.

But it turns out, we can do all these (declare a variable and assign a value to it) in just one line of code. …


With examples, let us find out what variables are, why do we need them and when to use them

Image for post
Image for post
A guide for beginners of any background to start writing codes

In our previous example, we built a program that greets us by our names. That was pretty exciting. But what if we want to change the name of the person to be greeted upon?

One could simply suggest changing the data quoted in (‘) to the name of the person. Sure, that could work if you don’t mind opening the file and making that change every time a new person comes in.

Introducing — the variables

Consider a variable as a container, a storage or simply a box that we use to store some data. The nature of a variable is that we are not sure what is going to be stored inside of it, but certainly, we need a place to capture and store some values and use it when needed. …


Why do we see examples of “Hello World”?

Almost always, the very first thing you learn from a tutorial is how to display “Hello World”.

But why?

Image for post
Image for post
A guide for beginners of any background to start writing codes

Like we learned previously, any line of codes within a program can be considered a line of instructions. We are instructing the computer to do what we want.

In the case of a “Hello World” example, we are simply instructing the computer to display something for us. …


One small step for me, One giant leap for the future

Image for post
Image for post
A guide for anyone to start writing codes

Learn the concept first

If you understand the concept of programming, you can learn any language at lightning speed.

If you had the experience of learning by following some online tutorials, you must have had this overwhelmed feeling from reading the first a few pages. All these meaningless instructions along with many oddly structured sentences just makes people want to give up after a few hours into the article.

Not if you learn them in the correct approach :)

I don’t encourage people to begin their learning process by remembering the syntax, the keywords and the use case without knowing “why” they even exist. It is rather the concept we first need to understand. …

About

Lucas F. Lu

Laravel Expert, AI enthusiasts. Recently fell in love with helping people rebuild their lives by learning how to program.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store