Continue statement not within a loop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>

using namespace std;

int main()
{
    int drinks;

    cout<<"Hello to the virtual Beverage Machine."<<endl;
    cout<<"Please choose your prefered beverage.\n";
    cout<<"1. Pepsi"<<endl;
    cout<<"2. 7Up"<<endl;
    cout<<"3. Uva"<<endl;
    cout<<"4. CocaCola"<<endl;
    cout<<"5. Bison"<<endl;
    cout<<":: ";
    cin>>drinks;
    cin.ignore();

        switch (drinks) {
        case 1:
        cout<<"You have chosen Pepsi";
        break;

        case 2:
        cout<<"You have chosen 7Up";
        break;

        case 3:
        cout<<"You have chosen CocaCola";
        break;

        case 4:
        cout<<"You have chosen RedBull";
        break;

        case 5:
        cout<<"You have chosen Bison";
        break;

        default:
        cout<<"You have chosen an invalid beverage.\n";
        cout<<"Please, press enter to choose again.\n";
        continue;

        }
    cin.get();
    return 0;
}


So the thing is, why am I getting the (Continue statement not within a loop.) error?

and if it is possible, how can i assign the (You have chosen) into a variable? because whenever I type in:
char chosen [25]= You have chosen
it always gets the (You) only..
Because the continue statement can only be within a loop
Use std::strings instead of char arrays.
continue stops the current iteration of the loop and goes straight to the next iteration, what exactly were you trying to accomplish with your continue statement?
Last edited on
I thought that (switch) was a loop statement.
and thanks for the advice..=)

and isnt the (continue statement) used to "continue" the loop?? or is it something else?
you guys have to go easy on me, am a total noob..yet=P
Like I said, continue quits the current iteration of a loop, so if a continue statement is before the functionality of the loop it won't do anything for that iteration. See below:

1
2
3
4
5
6
7
for (int i=1; i<=5; i++)
{
        if ( i == 3 )
                continue;

        std::cout << i << "\n";
}


this will output

1
2
3
4
1
2
4
5


make sense?
Topic archived. No new replies allowed.