473,796 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using break;???

I know that by some reasons... the use of "break;" in java language is not
correct, is there any similar problems with c#????
Aug 3 '06 #1
6 1729
David <Da***@discussi ons.microsoft.c omwrote:
I know that by some reasons... the use of "break;" in java language is not
correct, is there any similar problems with c#????
What do you mean by "not correct"?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 3 '06 #2
Something like this:

break is used only for switch statement control.

Reasoning: Using break, other than for switch statement control, makes it
difficult to later break a construct into smaller constructs or methods. It
also forces the developer to consider more than one end point for a
construct.

"Jon Skeet [C# MVP]" wrote:
David <Da***@discussi ons.microsoft.c omwrote:
I know that by some reasons... the use of "break;" in java language is not
correct, is there any similar problems with c#????

What do you mean by "not correct"?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 3 '06 #3
public static int[] CopyWithSquare( int[] val) {
int[] ret = new int[val.Length];
for (int i = 0; ; i++) {
ret[i] = val[i] * val[i];
if (ret[i] 200) {
break;
}
}
return ret;
}

relevant disassembly ... This looks about like what I would expect ... it
generates a compare + a jump out of the loop lines 32 + 3a

for (int i = 0; ; i++) {
00000015 xor edx,edx
00000017 mov ecx,dword ptr [ebp+4]
0000001a mov ebx,dword ptr [edi+4]
ret[i] = val[i] * val[i];
0000001d cmp edx,ecx
0000001f jae 00000048
00000021 mov esi,dword ptr [ebp+edx*4+8]
00000025 mov eax,esi
00000027 imul eax,esi
0000002a cmp edx,ebx
0000002c jae 00000048
0000002e mov dword ptr [edi+edx*4+8],eax
if (ret[i] 200) {
00000032 cmp dword ptr [edi+edx*4+8],0C8h
0000003a jg 00000041
for (int i = 0; ; i++) {
0000003c add edx,1
0000003f jmp 0000001D
break;
}
}

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************** *@msnews.micros oft.com...
David <Da***@discussi ons.microsoft.c omwrote:
>I know that by some reasons... the use of "break;" in java language is
not
correct, is there any similar problems with c#????

What do you mean by "not correct"?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Aug 3 '06 #4
As a general rule it is a good one but there are some cases where breaks
come in really handy.

It is similar to but not as extreme as the goto case it is best to avoid
them if possible but there are times where it can really help.

Cheers,

Greg
"David" <Da***@discussi ons.microsoft.c omwrote in message
news:17******** *************** ***********@mic rosoft.com...
Something like this:

break is used only for switch statement control.

Reasoning: Using break, other than for switch statement control, makes it
difficult to later break a construct into smaller constructs or methods.
It
also forces the developer to consider more than one end point for a
construct.

"Jon Skeet [C# MVP]" wrote:
>David <Da***@discussi ons.microsoft.c omwrote:
I know that by some reasons... the use of "break;" in java language is
not
correct, is there any similar problems with c#????

What do you mean by "not correct"?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Aug 3 '06 #5
David <Da***@discussi ons.microsoft.c omwrote:
Something like this:

break is used only for switch statement control.
No, break can be used in while, do/while, and for statements in both
Java and C#. You *may* choose not to use it other than for switch
statements, but it's a matter of taste.
Reasoning: Using break, other than for switch statement control, makes it
difficult to later break a construct into smaller constructs or methods. It
also forces the developer to consider more than one end point for a
construct.
However, it also means you don't have to code all code paths within the
loops to go through the whole loop body. There are various situations
where using break makes the code simpler rather than more complicated,
and I would fight against any "rule" telling me never to use it.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 4 '06 #6
I often use a break statement in a for loop for that looks for something I
need the index of. The index continues to increment until the item is found.
When it finds the item, it breaks. Afterwards, the value of the index is the
index in the array or Collection of the item, or, if it is equal to the
total count, the item was not found.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Who is Mighty Abbott? A twin-turret scalawag.

"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************** *@msnews.micros oft.com...
David <Da***@discussi ons.microsoft.c omwrote:
>Something like this:

break is used only for switch statement control.

No, break can be used in while, do/while, and for statements in both
Java and C#. You *may* choose not to use it other than for switch
statements, but it's a matter of taste.
>Reasoning: Using break, other than for switch statement control, makes it
difficult to later break a construct into smaller constructs or methods.
It
also forces the developer to consider more than one end point for a
construct.

However, it also means you don't have to code all code paths within the
loops to go through the whole loop body. There are various situations
where using break makes the code simpler rather than more complicated,
and I would fight against any "rule" telling me never to use it.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Aug 4 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1739
by: Mike Partridge | last post by:
Is it possible to access your caller's (not parent) context while inside a <xsl:template match...> or <xsl:for-each...>? Here is the xml I'm using: <report-set> ...<report> .....<detail-data> .......<detail-column position="1" dsc="col1" sum_fg="0"/> .......<detail-column position="2" dsc="col2" sum_fg="1"/> .......<detail-column position="3" dsc="col3" sum_fg="1"/>
40
4335
by: Elijah Bailey | last post by:
I want to sort a set of records using STL's sort() function, but dont see an easy way to do it. I have a char *data; which has size mn bytes where m is size of the record and n is the number of records. Both these numbers are known
9
10906
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent the wheel, right? Everything so far is working well with the Active Directory. The problem I am having is with adding File Permissions to a directory. I am currently using some code courtesy of "Willy Denoyette "
2
10225
by: memosa | last post by:
Hi, friends: This is my programme (work on Microsoft visual c++) and I have two question . First, I want to say that there is no error but I need a little help. This is a small programme about Bank : it's work but my question is (about 6-closing account) on function closing account....
7
3519
by: Peter Jansson | last post by:
Dear group, I have been struggling to get a simple program for inserting and extracting std::tm objects to/from streams to work. The code below tries to read a std::tm object from a std::istringstream but fails to do so, could anybody see what is wrong with the code? (Output follows the code.) I fear that I have not completely grasped how the time_getXXX methods should be used in the operator<< ? With best regards,
1
2052
by: Sam Samson | last post by:
Greeetings All .. For my users convenience I have mapped function keys F2 .. F12 to change the tabs on the Tabcontrol. Works like a charm <ominous musicuntil one hits F8</ominous music> That particular tabpage has a webbrowser object embedded in it .. and after it flicks to that tabpage it no longer plays nice with the other Tabpages .. click on another Tab using the mouse and all is wonderful again. (unless
1
1712
by: RubyRed | last post by:
Using SQL Server 2000. Basically, I am trying to calculate each minute of an employee scheduled time during their work shift. In the table below shows only the times that the shift begin (start_minute), ended (sched_endtime) and times (dtl_start_min, dtl_length, dtl_end_min) the employee went on Break, lunch, etc... What the table does not show is the times that the employee was not on any breaks, lunch etc.. that is called OPENTIME. I am...
0
1599
by: srinivas srinivas | last post by:
Hi, I am developing simple peer-peer RTC application for monitoring the SDP packets and i need to set the TLS security for the transport. But iam struggling to achieving this. Iam using IP addresses as SIP URI for communication. I am using IRTCClientProvisioning::GetProfile() IRTCClientProfile::EnablePrsenceEx() IRTCClientProvisioning::EnableProfileEx()
9
3395
by: ssubbarayan | last post by:
Dear all, I am in the process of implementing pageup/pagedown feature in our consumer electronics project.The idea is to provide feature to the customers to that similar to viewing a single sms message in a mobile device.With in the given view area if the whole message does not fit,we need to provide the ability for users to scroll through the entire message using pageup/pagedown or key up and key down.In our case we have the whole...
0
9683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9529
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10231
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10013
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7550
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4119
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.