It is rare to write a working program the first time you try. Do not worry about failing. To fail is to make your First Attempt In Learning. Mistakes in your code show that you are trying.
When we fail, we have an opportunity to learn from fixing the problem and this helps us to understand how things went wrong in the first place. If we make no mistakes, we may not learn about all the different ways to tackle a problem and may actually miss a better solution.
If you or your students are feeling a little deflated about code not working, remember to have a look at Failing is good video.
If we make no mistakes, we may not learn about all the different ways to tackle a problem and may actually miss a better solution.
Debugging is a systematic way for your students to iron out their mistakes. It is highly likely that your students will get something wrong and their code may not work the first time. At this stage, it might be tempting to leap in and try to solve the problem. Instead of giving them the answers, you should encourage your students to work through potential problems step-by-step, starting from basic issues and working up to more complex issues.
Here's a top tip, before checking code, always check hardware:
Once you have established these basic things are in place, you can start looking at the code line by line:
Remember to tell your students not to get disheartened by code not working the first time - in the coding world, failing is good!