PWM with potentiometer variable?

void setup()
{
pinMode(3,OUTPUT);
}

void loop ()
{
for (int i = 0; i < 100; i++)
{
analogWrite(3,i);
delay(50);
}
}

this is my current code but i would like to incorporate a 10k potentiometer to make a fan controller how would i accomplish this?

Read the pot with analogRead() returns 0-1023.
Write the PWM output with the value read divided by 4 (0-255).

im newer to arduino code, how would i define the analog read?

Suggest that you look at the examples in the IDE. There are some really basic examples that show how to read/write analog and digital values.

The 'Learning' and 'Reference' sections of this site are great for learning the basics. Have a look there and if you still have questions then let us know.

How do you have the fan connected to the Arduino ? I assume that you are not using the Arduino pin to drive the fan motor...

why don't you try this :http://arduino.cc/en/Tutorial/ReadAnalogVoltage#.UwQdCPl_t8E

or this first :http://www.arduino.cc/en/Tutorial/Potentiometer#.UwQcp_l_t8E