The goto statement in c++
We have gone through the while loop, for loop and do-while loop. The another way to do loop in c++ is through using the goto statement. The goto statement was used in olden days but it is not suitable for creating modern applications. But since c++ supports it, you should have knowledge about it, as you may encounter a c++ source code containing goto statements, in that case you will know what it is and how it works.
How the goto statement works?
It consist of label and statements that comes under that label. A label is named by you and it is followed by a colon sign (:). During execution of program, when goto is encountered, it jumps to the statements that comes under the label specified by goto statement. To get a clear idea, analyze the below program example.
/* A c++ program example that uses goto statement to display number from 0 to 9 */
#include <iostream>
using namespace std;
int main ()
{
int i=0;
loop:
cout << i << endl;
i++;
if (i<10)
goto loop;
return 0;
}
Why goto should not be used?
The use of goto should be avoided to make the program more readable and reliable. The goto statement can cause the program execution to jump to any location in source code and in any direction backward or forward. This makes the program hard to read and understand and also makes it difficult to find bugs.
Since now we have more tightly controlled and sophisticated loops like while loop, for loop and do-while loop, the use of obsolete statement like goto is not at all recommended in creating loops.
Please do comment if you don't understand any part or want to know more or just want to say thanks. I love programming and love to teach my friends. Your suggestions and appreciation will make this blog much better.
Want to learn more? View List Of All Chapters
create a program that will compute for employees daily salary using military time concept requirements rate=70.00 per hour ..to be display tax=0.5 ..grosspay : netpay:
ReplyDeletehelp me plssssss
create a program that will compute for employees daily salary using military time concept requirements rate=70.00 per hour ..to be display tax=0.5 ..grosspay : netpay:
ReplyDeletehelp me plssssss
And I m waiting for your next chapters
ReplyDeleteIt should be
ARRAYS AND POINTERS
USER DEFINED DATA TYPES (struct,enum,union,class)
DATA STRUCTURES
FUNCTIONS
---------------------------------------
OOPs Thory
OBJECTS AND CLASSES
ABSTRACTION AND ENCAPSULATION
POLYMORPHISM
INHERITANCE
STANDARD INPUT/OUTPUT
Using namespace statement
String classes
Templates
Standard C++ Library
CGI(Common Gateway Interface) Programming
http://clearnerz.blogspot.com/p/c-learnerz.html
DeleteGreat,.. Just add me guys :) crazymuffin0789@yahoo.com, i am biggner to c++, i love to program :) thanks for the info mr.homan
ReplyDeletevery useful post for C++ beginners
ReplyDeletei am a beginner of C++
Please keep on posting such quality articles as this is a rare thing to find these days. I am always searching online for articles that can help me. Looking forward to another great blog. Good luck to the author! all the best!
ReplyDeleteCelabright information
hallo sir i m hassan munir from pakistan and i m doing bscs in comsats university and i m little week in programming my problem is that i cant make the algorithm in programming plz tell me how i can improve the logic in programming beacuse i m the bigner in programming this is my first samester
ReplyDeleteGo through the books/blogs related programming basics. Do your basics well. Practice as much as you can. Don't just read the code, manually type it, compile it and run it and try to understand code by looking at the code.
DeleteDon't make haste, while you learn basics. Take your time, and practice well.
When i say do your basics well, i mean do "Control Statement" well. Control statement include : loops (for, while, do-while), if-else, switch-case, break, continue.
These are fundamentals of programming. And you will find these in all programming languages, with minor syntax differences. So if you understand these concept in one, you can get them in all.
i m watting for ur reply?
ReplyDeleteReplied! :D
DeleteThe Goto Statement is not advised in modern programming languages. But, It is a good article explaining the subject
ReplyDeletehttp://clearnerz.blogspot.com/p/c-learnerz.html
ReplyDeleteI'm sure that this post is useful for all young learners learning programming languages from scratch! Just have in mind that the best online writing services are 24/7 to help you with the ideas for learning!Good luck!
ReplyDeletePkjazba Provides Fashion Makeup Hairstyle Digests Recipes Fitness Health
ReplyDeletePkjazba.com
Pkjazba Provides Fashion Makeup Hairstyle Digests Recipes Fitness Health
ReplyDeletePkjazba.com
Wonderful, just what a blog it is! This blog has provided the helpful data to us continue the good work.
ReplyDeletetutorial for c++
This comment has been removed by the author.
ReplyDeletec++ examples on
ReplyDeleteAnalog Clock Samples
nice article for beginners.thank you.
ReplyDeletewelookups C++
javacodegeeks
Great stuff. Interesting post ever.
ReplyDeleteBest Event Planners in Pakistan
Nice Post....It will be helpful for beginner Student.Here is a blog for C++ Programming.
ReplyDelete