Okay, i am trying to figure out how to use the Continue, and Break flow controlls correctly, however i keep getting an error:

continue statement not within a loop or a switch
break statement not within a loop or a switch

My code:

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
 {
  srand ( (unsigned)time ( 0 ) );
  cout << "This program generates a random number\n"
       << "Press Y to continue.";
  int loopcount = 20;  
  char yes;
  cin >> yes;
  if (yes == 'Y' || yes == 'y')
  {
  int numb = rand() % 10 ;
  cout << "Your number is:\n";
  cout << numb
       << endl;
  }
  while(loopcount--);
  {
  if(loopcount < 0);
  {
  continue;
  }  
  if(loopcount == 0);
  {
  break;
  }
 }
  system("PAUSE");
  return 0;
}

remove the semi colon on line 22, you don't need semi colons after flow controls

Member Avatar for jencas

Same fault at line 28!

if (...);

is the same as

if (...) {;}

and just does nothing.

Aha it worked, Thanks much, cant believe i didn't notice that... :icon_eek:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.