switch case not exiting to rest of loop

sorry guys i am still new to this but i have a switch case in my main loop and it seems its not exiting to do the rest of the loop

in the main loop i am looking for a screen touch and it works fine but also i am trying to do other stuff in the loop and it seems to be stuck in looking for a screen touch only

i placed 3 Serial.print messages in the loop in set places and its only showing the first one over and over its never reaching the second and third. i know i might just be doing something silly but i cant see what

full loop code below

void loop() {
  Serial.println("begin loop");
  blueledBlink();
  
  // Wait for a touch 
  if (! ctp.touched()) {
    return;
  }

  // Retrieve a point  
  TS_Point p = ctp.getPoint();
  
 // flip it around to match the screen.
  p.x = map(p.x, 240, 0, 240, 0);
  p.y = map(p.y, 320, 0, 0, 320);

  int a = page;
     switch (a) {
  
     // --------------check to see if screen 1 is loaded-----------------
     
  case 1: {  // Screen 1 Active As when screen 1 loads it chages the value of page to 1
  
  if ((p.x > 175 && p.x < 201)&& (p.y > 280 && p.y < 320))
  setuser();
  
    else if ((p.x > 144 && p.x < 163)&& (p.y > 280 && p.y < 320)) 
   systest();       
         
   else if ((p.x > 104 && p.x < 116)&& (p.y > 280 && p.y < 320)) 
   fonafalt();
   
      else if ((p.x > 58 && p.x < 72)&& (p.y > 280 && p.y < 320)) 
   Serial.print("option1.3");
   
      else if ((p.x > 5 && p.x < 39)&& (p.y > 280 && p.y < 320)) 
   Serial.print("option1.4");
 break;}
   
   // -----------------check to see if screen 2 is loaded------------------

     
  case 2: {  // Screen 1 Active As when screen 1 loads it chages the value of page to 1
  
  if ((p.x > 175 && p.x < 201)&& (p.y > 280 && p.y < 320))
  Serial.print("option1.4");
  
    else if ((p.x > 144 && p.x < 163)&& (p.y > 280 && p.y < 320)) 
   setuser();       
         
   else if ((p.x > 104 && p.x < 116)&& (p.y > 280 && p.y < 320)) 
   Serial.print("option1.2");
   
      else if ((p.x > 58 && p.x < 72)&& (p.y > 280 && p.y < 320)) 
   Serial.print("option1.3");
   
      else if ((p.x > 5 && p.x < 39)&& (p.y > 280 && p.y < 320)) 
   mainmenu();
 break;}
   
   // -----------------check to see if screen 3 is loaded------------------
   


     
  case 3: {  // Screen 1 Active As when screen 1 loads it chages the value of page to 1
  
  if ((p.x > 175 && p.x < 201)&& (p.y > 280 && p.y < 320))
  Serial.println("one");
  
    else if ((p.x > 144 && p.x < 163)&& (p.y > 280 && p.y < 320)) 
   setuser();       
         
   else if ((p.x > 104 && p.x < 116)&& (p.y > 280 && p.y < 320)) 
   Serial.print("option1.2");
   
      else if ((p.x > 58 && p.x < 72)&& (p.y > 280 && p.y < 320)) 
   Serial.print("option1.3");
   
      else if ((p.x > 5 && p.x < 39)&& (p.y > 280 && p.y < 320)) 
   Serial.print("option1.4");
 break;}
 
    // -----------------check to see if screen 4 is loaded------------------

     
  case 4: {  // Screen 1 Active As when screen 1 loads it chages the value of page to 1
  
  if ((p.x > 175 && p.x < 201)&& (p.y > 280 && p.y < 320))
  Serial.println("one");
  
    else if ((p.x > 144 && p.x < 163)&& (p.y > 280 && p.y < 320)) 
   setuser();       
         
   else if ((p.x > 104 && p.x < 116)&& (p.y > 280 && p.y < 320)) 
   Serial.print("option1.2");
   
      else if ((p.x > 58 && p.x < 72)&& (p.y > 280 && p.y < 320)) 
   Serial.print("option1.3");
   
      else if ((p.x > 5 && p.x < 39)&& (p.y > 280 && p.y < 320)) 
   Serial.print("option1.4");
 break;}
 
  Serial.println("!!!!!!!! END CASE !!!!!!!!");
     }
 // ---------------------End Screen check ------------------------------------  
 
  
// Print out raw data from screen touch controller for debug use only
//  
//  Serial.print(" X "); Serial.print(p.x);
//  Serial.print(" & Y "); Serial.print(p.y);
//  
//  Serial.print("  Page Value= "); Serial.print(page);
//  Serial.println();
//  delay(500);
  
Serial.println("!!!!!!!! RELLY END loop !!!!!!!!");
 }

A 'return' exists the function. So if the 'return' is executed, the loop() exists and the loop() is started again.

This code is unknown: int a = page ; The variable 'page' does not exist, its value could be zero. Add a "default:" to the switch statement, and print the value of 'a' or the value of 'page'.

The '{' and '}' are not used for every "case 1:", "case 2:" and so on. But I don't know if they can hurt.

switch(a)
{
case 1:
  break;
case 2:
  break;
}

You should use indents in the sketch consistant, that would make it better to read. There is an auto-text-format in the menu.

Peter_n: A 'return' exists the function. So if the 'return' is executed, the loop() exists and the loop() is started again.

This code is unknown: int a = page ; The variable 'page' does not exist, its value could be zero. Add a "default:" to the switch statement, and print the value of 'a' or the value of 'page'.

The '{' and '}' are not used for every "case 1:", "case 2:" and so on. But I don't know if they can hurt.

switch(a)
{
case 1:
  break;
case 2:
  break;
}

You should use indents in the sketch consistant, that would make it better to read. There is an auto-text-format in the menu.

page value is changed when a screen is loaded. so when the main page loads page =1 and the second screen load page =2

it the only way i could keep track of the menu options on each page as i have 5 options on each page and the buttons are always in the same place. so if button one is pressed and i am on page 2 it may do action A but if page 2 is loaded and the same button is pressed it can now do action B

and yes once the code is completed or gets too much for me to read i will start cleaning it up

im getting close to that stage now over 1500 lines of code and im finding my self scrolling up and down looking for certain parts.

i wish i could collapse the functions i have done but there is no need for me to read anymore. that could be a nice little add on to sketch

I suggest to add a "default:" to the switch-statement, and show an error message there for an invalid 'page' value.

Arduino IDE 1.6.5 can collapse parts of the source code. You have to enable it in the settings: "Enable code folding". You could move some code to other tabs. There is a drop-down menu in the upper-right corner. Choose "New tab" and give it a name like "display" or so (you don't need to give it an extension). In your project a new file "display.ino" will be created.

The sketch for my Arduino Mega (it is the central control unit in my home) has now more than 20 tabs. I have the code very well seperated, so a bug in one part can not mess up the other part.

P.S.: You don't have to quote my reply, since it is already there ;)

Again it has to be said: post the whole sketch… Your car breaks down you take the
whole car to the garage to be fixed, not just the steering wheel!

thanks again that worked a treat and i didn't see the fold function option until now great job