Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Monday, March 23, 2020

goto statement in C:

go to statement: is also known as jumping statement in c language, which transfer the program's control from one statement to another statement

goto statement | welcome2protec.com


go to statement: is also known as jumping statement in c language, which transfer the program's control from one statement to another statement where label is defined. It can be used to repeat some part of the code for a particular condition.



However, The goto statement is rarely used because it makes program confusing, less readable and complex. Also, when this is used, the control of the program won’t be easy to trace, hence it makes testing and debugging difficult.


Syntax: go to statement

label_name:   
//some part of the code;   
goto label_name;

The label is an identifier. When the goto statement is encountered, the control of the program jumps to label: and starts executing the code.


Flow Chart of goto statement:

goto statement | welcome2protec.com
goto statement | welcome2protec.com

Let's understand with a simple example.

Example 1: goto statement

#include <stdio.h> 
#include <conio.h> 
void main ()  
{  
    printf("Welcome to Protec\n");
    goto out;  //Here, goto statement is occurred
    printf("IT Training Center");
    printf("At Tara Market, beside Vishal MegaMart-Siwan");
    out:  
        printf("welcome2protec is a free online IT tutorial site!");    
    getch();  
 }  

Explanation: In this example, When the goto statement is encountered, the control of the program jumps to label_name, out: and starts executing the code (welcome2protec is a free online IT tutorial site!).

Output

welcome2protec is a free online IT tutorial site!

Example 2: goto Statement

#include <stdio.h> 
#include <conio.h> 
void main ()  
{  
    int marks;
    clrscr();
    printf("Please Enter  your marks:");
    scanf(""%d", &marks);  
    if(marks >= 50)  
    {  
       goto pass;  
    } 
    else
    {
       goto fail;
    } 
    pass:
    printf("Congratulation! You have passed the exam.\n", num); 
    fail: 
    printf("Sorry! Better luck next time.");
    getch();  
}  

Output

Please enter your marks: 30
Sorry! Better luck next time. 












Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us