a problem with the loop section of the sketch

hi guys, I program the atmega328 through duemilanov and from some reason when I put few functions in the loop section, only the first function does work.
tried to put these functions all together in the setup section and then everything works just great.
why is that?
by the way, tried to put all the functions in a general function and enable that general function that includes the wanted functions, but the same happens again..

here is the problematic code:
(tried here to put both the functions all together in the same function - these two functions are two for loops.. and just the first loop does work and the second doesn't.)

//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;

void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}

void gamba()
{
// count from 0 to 255 and display the number
// on the LEDs
for (int numberToDisplay = 0; numberToDisplay < 32768; numberToDisplay++) {
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);

//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
// pause before next value:
delay(1);
}

delay(1000);
for(int f=0;f<6;f++)
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, 65535 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, 65535);
digitalWrite(latchPin, HIGH);
}
delay(1000);
}

void loop() {
gamba();
}

goldami1:
by the way, tried to put all the functions in a general function and enable that general function that includes the wanted functions, but the same happens again..

If you run your for() loops in the opposite direction, does the behavior change? Have you tried adding Serial.print()s to verify if the loops are running? You may not visually seem them.

I'll try, thanks.

I'm getting tired of typing this. Literals, like 32768, are interpreted as ints, unless you specify otherwise. You haven't, so 32768 is interpreted as, and stored in an int register. Now, look at the range of values that can be stored in an int, and try to figure out what happens when you stuff a value in that is too large. Now, what does this do to your loop?