473,385 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

can i use continue inside if loop?

b1: if(){

sstmts;
continue b1;
}
Mar 4 '07 #1
6 21364
DeMan
1,806 1GB
As far as I know the inside of loops is the ONLY place you can use a continue. I hope you realsie, however, that continue means "lets get on with the next iteration"
In other words if you had the following code:
Expand|Select|Wrap|Line Numbers
  1. for(a=start; a< finish; a=a++)
  2. {
  3.   myValue=importantValue();
  4.   if(myValue==SOME_IMPORTANT_CONSTANT)
  5.   {
  6.     continue;
  7.   }
  8.   doSomething();
  9. }
  10.  
then "doSomething" would NOT be executed in the case tahat we reached the continue statement.
If you want something more like "if(some case) doNothing else doSomething", then consider rephrasing the if to be "if (!(some case))" OR alternatively, have an empty if (whioch is not considered good practice but is syntactically legal)
Expand|Select|Wrap|Line Numbers
  1. if(!dontCareValue)
  2. {
  3.   betterDoSomething();
  4. }
  5.  
  6.  
  7. /* Or a not so clean solution */
  8.  
  9.  
  10. if(dontCareValue) /* do nothing for if (we could omit {} and use ; if we really wanted */
  11. {}
  12. else
  13. {
  14.   betterDoSometing();
  15. }
  16.  
Mar 4 '07 #2
hirak1984
316 100+
you can put continue inside if( rather you should put it inside an if)

only when the if itself is in any loop.
b1: if(){

sstmts;
continue b1;
}
Mar 4 '07 #3
r035198x
13,262 8TB
May I just say that it is very bad practice to use continue statements.
Mar 5 '07 #4
DeMan
1,806 1GB
You certainly can, and reading this post I was wondering whether you've ever come accross a case where you need it (I've used break WAY too many times, but never continue)
Mar 5 '07 #5
Ganon11
3,652 Expert 2GB
I used continue in Chess. Basically, when there's an error in getting the move from a player, I want to skip any statements that will use this bad input, but I don't want to end the game. I use continue to go back to the start of the loop where I get input.

You could also use it in the following scenario: Check the numbers 1 through 10 to see if a number is prime. IF it is prime, do x number of new calculations on it, ELSE, don't do anything - but keep checking. You could use a large if statement to make sure the operations are only done IF x is prime, or you could use a continue statement.
Mar 5 '07 #6
ria3
8
You could make several if loops inside a while loop.
Mar 5 '07 #7

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

Similar topics

2
by: Michael Satterwhite | last post by:
I *MUST* be overlooking something obvious. Consider the following code: foreach($_POST as $key=>$value) { print "$key=>$value<br />"; if(! empty($value)) { switch($key) { case "Submit": case...
5
by: Glen Wheeler | last post by:
Hello All. I've been coding in python for a reasonable amount of time now (coding in total for approx. 20 years) and am writing a performance intensive program in python. The problem I'm having...
5
by: Ann | last post by:
I have trouble sometimes figuring out where break and continue go to. Is there some easy way to figure it out, or a tool? TIA Ann
6
by: Bern | last post by:
lets say i have the code: while (some condition){ /* the "big" loop */ .... some code.... while (some condition){ ...code... if (!some condition){
14
by: Daniel Bass | last post by:
is there an equivalent key word for C++'s "continue" in VB (.net) in this context? CString szLine; szLine = myReader.ReadLine(); while ( !szLine.IsEmpty() ) { if ( szLine(0) == '-' ) {
15
by: PagCal | last post by:
Is this language missing the functionality of a C/C++ 'continue' statement? For example: While NOT isEof() If condition ' a C or C++ continue would work here ' but we are forced to use a...
25
by: v4vijayakumar | last post by:
'continue' within switch actually associated with the outer 'while' loop. Is this behavior protable? int ch = '\n'; while (true) { switch(ch) { case '\n': cout << "test"; continue; } }
6
by: Gary Wessle | last post by:
Hi using the debugger, I happen to be on a line inside a loop, after looping few times with "n" and wanting to get out of the loop to the next line, I set a break point on a line after the loop...
5
by: Deepak | last post by:
I am programing a ping application which pings various centers . I used timer loop and it pings one by one. Now when i finish pinging one center it should wait for the ping_completed function to...
36
by: mdh | last post by:
May I ask the group this somewhat non-focused question....having now seen "continue" used in some of the solutions I have worked on. ( Ex 7-4 solution by Tondo and Gimpel comes to mind) Is there a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.