Out of interest - why did missing this one line of code out cause this problem?

I’ve just been doing a Crystal Ball project using an LCD.
In the void setup section it should have said “Ask the Crystal Ball”, and then going to the loop, on sensing the tilt switch being activated, come up with one of 8 answers, randomly picked. It was doing it all fine, apart from not saying “Ask the Crystal Ball”. I checked everything over and over and couldn’t fathom it, until lo and behold, realised I had missed a line of text out. I added it, and all is fine!

I’ve attached screenshots of the code. The line I missed was "if (switchState==LOW);

I’m a beginner, so purely for my own curiosity and to try and learn and understand more,what was the significance of that particular line? Why did it not print the message in the setup?

Thanks!

PS Sorry about the silly, slightly rude answers - I was doing this project with my 6 year old son and I let him choose the answers!!

  if (switchState==LOW)
    ;

That statement does nothing so it should not matter if it was there or not. Did you mean to say that you had used:

  if (switchState !=prevSwitchState) {

where you should have used

  if (switchState==LOW && switchState !=prevSwitchState) {

?

Please use code tags ("</>" button) to post code properly.

Using the 'copy for forum' feature in the IDE Edit menu, copy the malfunctioning sketch and paste it into a new post. Use ctrl+t to format the sketch (adjust indents, etc.) before copying.

FYI, the sketch is available for copy/paste in IDE->file/examples/starterkit_basickit

johnwasser:

  if (switchState==LOW)

;




That statement does nothing so it should not matter if it was there or not. Did you mean to say that you had used:



if (switchState !=prevSwitchState) {



where you should have used 


if (switchState==LOW && switchState !=prevSwitchState) {



?

No, I didn't use

  if (switchState==LOW && switchState !=prevSwitchState) {

I used

  if (switchState !=prevSwitchState) {

then added

  if (switchState==LOW);

when I realised I had missed it, from reading through the code in the book.

Thanks to the posters for telling me how to put code in here :slight_smile: Will try and do that in future!