This page gives a number of simple programming exercises and solutions which will help you learn to write for loops, while statements and if-else statements. There are solutions to some of the exercises, but use them only after you have made a good attempt to solve the exercises yourself. The point is to introduce a minimum amount of syntax for these languages and get you solving small programming problems. This page is not attempting to teach much about these languages, and deliberately avoids using specialized commands in favor of simpler but universal programming ideas. If you find this page useful and would like to contribute additional exercises or solutions, perhaps in other languages, please contact
I recently watched a talk about by Terry Yin. As I finished university and are now working as a full time web developer I felt the need to keep on learning and improving my programming skills actively. Yin talks about different types of programming exercises with all their advantages and disadvantages. He especially mentions two websites with small to extensive exercises:
So you see, no matter how much you think you know, without doing any exercises, you can’t lose weight. For the sake of losing weight, get out your paper and start doing the following exercises, will ya?
In this chapter we are to go through a set of programming exercises. They are all real world problems which are interesting to solve.
We’ll be applying the four step model to these exercises so you’ll see how efficient it’ll help you code!
The PHP programming exercises progress from the simplest scripts ("Hello world!") to more complex. More difficult requests build on skills included in earlier ones. If you jump ahead and find yourself stuck, go back one or two. Be sure to read the comments in the answer script for some explanation. If you find that a different approach gets the same results, great! Just be sure you understand the PHP syntax the problem was designed to test.