By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

break out of if + for statement without going to else?

P: 5
Hi, I can't figure something out :P
Is it possible to break out of a if statement while keeping the else condition?
Maybe looking at the code, it'll make more sense for you since i don't know how to describe my problem...

This is a function that takes in strings and it comes from a class...
Right now, it would output something everytime it hits a string that's the same as the foundname, and stuffies everytime it doesn't match the string name,
what i want is if i can have one(either the "if" or the "else" part) and not the other.

Thanks a lot!

Expand|Select|Wrap|Line Numbers
  1.    void findname(string foundname){
  2.       if(name==foundname){
  3.           for(int counter=0;counter<add;counter++){
  4.              cout<<"something"<<endl;
  5.           }
  6.       }
  7.       else{
  8.           cout<<"stuffies"<<endl;
Mar 20 '07 #1
Share this Question
Share on Google+
1 Reply

P: 2,476
what i understood that is ......

//Some code
//u r using break here
//some code

if the break statement executed then u want the control out of if condition...

m i right ???????

but it is not possible..... welcome again
Mar 20 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.