Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

start reading code from specific line

+5 votes
asked Jun 13 by Wryyy!! (430 points)
Hello,
is there a way to tell the program to start reading code from a specific line? or something like that?

I try to use a loop but it didn't work.

here is an example :

printf ("hello\n");
printf ("toto\n");
[ligne to execute program from ligne 2 ]
---------------IN CMD-----------
hello
toto
toto

1 Answer

+3 votes
answered Jun 13 by Peter Minarik (34,450 points)
selected Jun 14 by Wryyy!!
 
Best answer

goto makes your code jump into a specific line (marked with a label).

However, goto makes your code very hard to read/understand. So I'd advise against it. There are usually better ways to deal with this. E.g. loops:

#include <stdio.h>

int main()
{
    printf("No-repeat\n");
    for (int i = 0; i < 2; i++)
        printf("Repat twice\n");

    return 0;
}
commented Jun 14 by Wryyy!! (430 points)
Thanks for the answer :)
commented Jun 22 by Nikhil Kumar (100 points)
#include <stdio.h>

int main ()

{

    printf("hello");

    for(int i=0;i<2;i++)

    {

         printf("totto");

    }

  return 0;

}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...