If else error

I keep getting an error on the “else” line. What am I missing?

if (rtd = 1); { readrtdmash(); } else { readmash(); }

if (rtd == 1) looks like you doing assignment not evaluation is this a forum typo

Short answer, your code should look like this:

if (rtd == 1) { readrtdmash(); } else { readmash(); }

Not a typo, just bad programming. I have the variable rtd <- 0 (or 1 depending on the sensor type) earlier in the code. So rtd = 1 would set it vs rtd == 1 would verify that rtd is or is not equal to 1?

@beardedinventor I keep getting “expression expected” error on the else line.

Longer answer - there a two things wrong with the code:

  1. You’re using the assignment operator (=) instead of the comparator operator (==). The assignment operator casues rtd to be assigned a value of 1, instead of checking to see if rtd is equal to 1.

  2. You have a semicolon after your if statement. The semicolon is interpreted as an empty line of code directly after the if statement. The reason you’re getting an error on the else line, is that your code is being interpreted like this (assuming we fixed 1):

`if (rtd == 1) {
; //no-op


else {

Ahh cool thanks! Everything seems to be working including the ability to switch between the currently broken RTD breakout code and the actually working thermocouple code using a @makedeck TC breakout!

Don’t forget that you can leave out the semi-colons (:wink: too. Squirrel lets you use these, but it’s perfectly happy if you don’t. I now leave these out: code looks clearer, and you can’t put one where it shouldn’t be.