"else' without a previous 'if'"

Here's the code:

void loop()
{
if (analogRead(A1) <=50); {
pinMode(6, OUTPUT);
digitalWrite(6, HIGH); }
else {
pinMode(6, INPUT_PULLUP;
}
}

Why do I get the following error message:
"'else' without a previous 'if'"
(?)

Two mistakes.

  1. A semicolon where there shouldn't be. if (analogRead(A1) <=50); {
  2. A missing parethesis. pinMode(6, INPUT_PULLUP;

The corrected version:

void loop()
{
  if  (analogRead(A1) <= 50)  {
    pinMode(6, OUTPUT);
    digitalWrite(6, HIGH);
  }
  else {
    pinMode(6, INPUT_PULLUP);
  }
}

edit: Why are you switching between a driven HIGH output to an input with a pullup resistor? Both are HIGH.

Thank's to you, Surfer Tim;
it solved the problem... I went deeper and added these (* 4)
"{
if (analogRead(A1) <=50 && analogRead(A5) >150) {
pinMode(6, OUTPUT); //East1a
digitalWrite(6, LOW); }
else {
pinMode(6, INPUT_PULLUP);
if (analogRead(A1) <=50 && analogRead(A5) <=50) {
pinMode(13, OUTPUT); //East1b
digitalWrite(13, LOW); }
else {
pinMode(13, INPUT_PULLUP);
}
}"
It works ok: when I push A1 without A5, I light '6" and when I push A1 with A5, I light '13' but after one cycle, if I let A5 'off' and leave A1 'on' most of the time it lights both output. I've tried to include "pinMode(xx, INPUT_PULLUP); before each output command but it does'nt correct the problem ??? Note that when I let go all switches, the process that I talked about just redo...

Whatever else is going on you don't need the pinMode() commands just before writing to the pins or reading from them. Unless, of course, in the code that you have not posted you have changed their pinMode() for some reason.

Please post your whole program and when you do use code tags (</> icon) to make it easier to deal with.

Here are the code:
The pupose of it is to minitor a 4 position jogstick with a top switch that makes the 4 positions to send to a different group (Ref A5)
// Ref "Bob_if_else"
// In the "Bob exemple" list;
// this portion monitors the 5 ins and sends to 8 different outs
// Built on april 10, 2016
// by Robert Boivin

void setup()
{
pinMode(A1, INPUT_PULLUP); //
pinMode(A2, INPUT_PULLUP); //
pinMode(A3, INPUT_PULLUP); //
pinMode(A4, INPUT_PULLUP); //
pinMode(A5, INPUT_PULLUP); //

pinMode(2, INPUT); //
pinMode(3, INPUT); //
pinMode(4, INPUT); //
pinMode(5, INPUT); //
pinMode(6, INPUT); //

pinMode(9, INPUT); //
pinMode(10, INPUT); //
pinMode(11, INPUT); //
pinMode(12, INPUT); //
pinMode(13, INPUT); //
Serial.begin(9600); //
}
void loop() {
if (analogRead(A1) <=50 && analogRead(A5) >150) {
pinMode(6, OUTPUT); //East1a
digitalWrite(6, LOW); }
else {
pinMode(6, INPUT_PULLUP); // The reason I change "OUT6" to "IN6"
if (analogRead(A1) <=50 && analogRead(A5) <=50) { // is that I'm driving 3.3V processor inputs.
pinMode(13, OUTPUT); //East1b // I don't want some +5V to be present
digitalWrite(13, LOW); } // So changing it that way solves all of that
else {
pinMode(13, INPUT_PULLUP);
}
}
if (analogRead(A2) <=50 && analogRead(A5) >150) {
pinMode(5, OUTPUT); //North1a
digitalWrite(5, LOW); }
else {
pinMode(5, INPUT_PULLUP);
if (analogRead(A2) <=50 && analogRead(A5) <=50) {
pinMode(12, OUTPUT); //North1b
digitalWrite(12, LOW); }
else {
pinMode(12, INPUT_PULLUP);
}
}
if (analogRead(A3) <=50 && analogRead(A5) >150) {
pinMode(4, OUTPUT); //West1a
digitalWrite(4, LOW); }
else {
pinMode(4, INPUT_PULLUP);
if (analogRead(A3) <=50 && analogRead(A5) <=50) {
pinMode(11, OUTPUT); //West1b
digitalWrite(11, LOW); }
else {
pinMode(11, INPUT_PULLUP);
}
}
if (analogRead(A4) <=50 && analogRead(A5) >150) {
pinMode(3, OUTPUT); //South1a
digitalWrite(3, LOW); }
else {
pinMode(3, INPUT_PULLUP);
if (analogRead(A4) <=50 && analogRead(A5) <=50) {
pinMode(10, OUTPUT); //South1b
digitalWrite(10, LOW); }
else {
pinMode(10, INPUT_PULLUP);
}
}
}

Thanks for the code but you took no notice of the advice to use code tags.
Your code would be so much easier to understand if you used names for the pins. You have gone to the trouble of adding comments so why not use names ?

Can you please expand on your reasons for changing the pinMode()s in the loop() function ?

You are right ... I'll get there!

pinMode(6, INPUT_PULLUP); // The reason I change "OUT6" to "IN6"
if (analogRead(A1) <=50 && analogRead(A5) <=50) { // is that I'm driving 3.3V processor inputs.
pinMode(13, OUTPUT); //East1b // I don't want some +5V to be present
digitalWrite(13, LOW); } // So changing it that way solves all of that

From the recent reply... (at least for now)