Help with "for" statement

So, I'm learning how to use each of these functions and wanted to us "for" to create a simple calculator. Here's my code, and it keeps saying "error: expected `)' before '{' token."

The goal of this code is to make it set x=1 whenever digitalRead(2) == High, but I can't get it to work. Anybody know what's wrong?

int x = 0;
int y = 0;

void setup()
{
pinMode(2,INPUT);
Serial.begin(9600);
}

void loop() 

{
  for (digitalRead(2) == HIGH);
{  x = 1;
  break;
}
{ 
delay(1000);
Serial.print(x);
}}

I think you need to read up on http://arduino.cc/en/Reference/For and http://arduino.cc/en/Reference/If

(deleted)

Then how do I get it to break the loop? I made it kinda work with the if statements before, but I want it to get a value for X then stop looking. here's what I had before.

This will constantly find a new x, but how do I get it to stop after it get's the input?

int x = 0;
int y = 0;

void setup()
{
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(0,OUTPUT);
Serial.begin(9600);
}
void loop()
{
  
  if (digitalRead(0)== HIGH)
  (x=0);

  
  if (digitalRead(2)== HIGH)
  (x=1);
  delay(100);

  if (digitalRead(3)== HIGH)
  (x=2);

  if (digitalRead(4)== HIGH)
  (x=3);

  if (digitalRead(5)== HIGH)
  (x=4);

  if (digitalRead(6)== HIGH)
  (x=5);

  if (digitalRead(7)== HIGH)
  (x=6);

  if (digitalRead(8)== HIGH)
  (x=7);

if (digitalRead(9)== HIGH)
  (x=8);

  if (digitalRead(10)== HIGH)
  (x=9);

delay(100);
    Serial.print(x);
}
if (digitalRead(2)==HIGH)
  x = 1;
else 
  x = 0;

What do you need it to loop for?

ok, that would make sense except I don't know how to enter that without it constantly repeating in that "void loop"

if (digitalRead(5)== HIGH)
  (x=4);

  if (digitalRead(6)== HIGH)
  (x=5);

I'm seeing a pattern here (I'm also seeing unnecessary parentheses). A for loop and some simple arithmetic looks the way ahead (arrays really are the way ahead, but that's some way off)

Not sure why pin 2 alone has a delay.

wiiman3893: ok, that would make sense except I don't know how to enter that without it constantly repeating in that "void loop"

When, exactly, do you want it to repeat? Do you want it run just once? Whenever you shake it or shine a light on it, every other 3 minutes?

When I connect the voltage to pin 2, I want it to set x=1. I want it to wait for an input, then use that input later. Eventually each pin corresponding to a number. So that connecting it to pin 3 will make x=4, etc.

So why don't the other pins have a delay?

Explain what you want to do, not how you think you ought to do it.

(If you want to use the serial port for other things, I suggest you don't use pin zero)

Ok, here is what I’m trying to do. (I am VERY new to this, I’ve been doing this for 2 days now so please bear with me.)

I have a loop running, with a series of IF statements. Each statement is checking the pins for their voltage, and if a certain pin is connected to the voltage, it will assign x the new value associated with that pin. The problem is that I can’t find much reference on this sort of thing and don’t know how to make it break the loop. I want to make it so that when I connect the voltage to pin 2, it will assign x it’s new value. then it will stop searching the pins for a voltage and store the x value.

Rarely is it a good idea to halt execution altogether like you're asking. You're better off designating a state variable that will keep track of if you've found your value. Example:

void loop() {
  static short x=0;
  static short gotInput=0; // no input yet

  if (digitalRead(2)==HIGH) 
  {
    gotInput=1; // we got an input
    x=1; // set our x value
  }

  if (gotInput) 
  {
    // Do stuff now that we got an input
    // Set gotInput back to 0 when you need to wait for the input again
  }
}