Custom Toast

Reading Time: 7 minutes In this tutorial we are going to show you how you can create easily a Toast message with a custom layout like below. Step 1 – Create new project Our first step is to create a whole new project. For this, launch Android Studio. If you see the “Welcome page”, then click on the “Start a new … Read more

Android Pong

Reading Time: 8 minutes
In this tutorial we will create the world oldest game, the Pong, but in our case we give it the name Android Pong. We will use the Android Canvas to draw first a black background rectangle and this will give space for our Android Pong game.

Android Pong is a very simple game, as you can see on the picture. It will have at the left top corner a text. This will show the current points. Next to the text will be the start position of our ball. The player shape is a rectangle at the bottom of the playground.

Read more

Follow and like us:

Break Expression

Reading Time: 3 minutes

Suppose that you are working with loops. It is sometimes desirable to terminate the loop immediately without checking the test expression. In such case, break is used. It terminates the nearest enclosing loop when encountered (without checking the test expression).

How break works?

Almost always it is used with if..else statements. For example: If expression is evaluated to true, break is executed which terminates the for loop.

Read more

Follow and like us:

Recursion and Tail Recursion

Reading Time: 3 minutes

A function that calls itself is known as recursive function. This technique is known as recursion. A physical world example would be to place two parallel mirrors facing each other. Any object in between them would be reflected recursively.

How does recursion work in programming?

Here, the recurse() function is called from the body of recurse() function itself. Here’s how this program works.


Example

Here, the recursive call continues forever causing infinite recursion. To avoid infinite recursion, if…else (or similar approach) can be used where one branch makes the recursive call and other doesn’t.

Read more

Follow and like us:

Continue Expression

Reading Time: 3 minutes

Suppose you are working with loops. It is sometimes desirable to skip the current iteration of the loop. In such case, continue is used. The continue construct skips the current iteration of the enclosing loop, and the control of the program jumps to the end of the loop body.

How continue works?

Almost always it is used with if..else statements. For example: If the expression is evaluated to true, continue is executed which skips all the codes inside while loop after it for that iteration.

Read more

Follow and like us:

stay informed!

Subscribe to receive exclusive content and notifications