473,386 Members | 1,796 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,386 software developers and data experts.

while and goto

this loop will execute 5 times, correct?

for(i = 0; i < 10; i++)
{
if ( i == 5 )
goto end;
}

end:
Mar 24 '06 #1
6 2102

Jessica Weiner wrote:
this loop will execute 5 times, correct?

for(i = 0; i < 10; i++)
{
if ( i == 5 )
goto end;
}

end:


6

Mar 24 '06 #2
Jessica Weiner wrote:
this loop will execute 5 times, correct?

for(i = 0; i < 10; i++)
{
if ( i == 5 )
goto end;
}

end:


It depends on what you mean. The body of the loop will be entered six
times. Any code added to the end of the loop body would be executed
five times (assuming it doesn't do anything to affect flow control).
Under either interpretation, I'd argue the loop is only executed once.
Mar 24 '06 #3
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
for(int i=0; i<10; i++)
{
cout << i + 1 << endl;
if(i == 5)
goto end;
}
end:
cout << "Out of loop";
return 0;
}
Should give you the answer..

Mar 24 '06 #4
It will display output as
1
2
3
4
5
6
Out of loop

Mar 24 '06 #5
6

Mar 24 '06 #6
Jessica Weiner wrote:
this loop will execute 5 times, correct?


Get yourself a C++ compiler and found out!

Stewart.

--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS-
PE- Y? PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox. Please keep replies on
the 'group where everyone may benefit.
Mar 24 '06 #7

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

Similar topics

33
by: Diez B. Roggisch | last post by:
Hi, today I rummaged through the language spec to see whats in the for ... else: for me. I was sort of disappointed to learn that the else clauses simply gets executed after the loop-body -...
52
by: Rick | last post by:
Hi, For portability, can an issue arise if we use while(1) for an infinite loop in C? If so, should we then use for(;;)? Thanks, Rick
36
by: invni | last post by:
I have a nested while. How do I go from the inner while to the beginning of the outer while? Can this be done without using goto? while_1() { some codes here while_2() { if true go to the...
30
by: Felix Kater | last post by:
Hi, in some cases like dynamic memory allocation I find it convenient to (ab-)use for() or while() like this: /* (allocate memory) */ for(;;){ /* alternatively: while(TRUE){ */
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...
2
by: Carl Cerecke | last post by:
Well, it doesn't quite rule them all, but it is fast: About three times faster than using one function per state. Faster than using generators. Faster than using code objects. Some, possibly...
14
by: Jan Schmidt | last post by:
Hi, in a nested do-while-loop structure I would like to "continue" the outer loop. With goto this should be no problem in while-loops. However, for do-while I cannot get it to work (without a...
1
by: somenath | last post by:
Hi All, I have doubt regarding how compiler understands about while loop. For example the bellow mentioned code produce the output as mentioned bellow. #include<stdio.h> int main(void) {
12
by: desktop | last post by:
Are there any performance issues between: bool run = true; while(run) { if (bob1 &&){ //dothing break; }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.