Questions tagged [goto]

In imperative programming, a "go to" statement is an unconditional jump instruction that changes the flow of control to the point of the program referenced by the "go to" statement.

1057 questions
-4
votes
6 answers

Some questions about "goto" in C language

I have some question about goto.Here is my code: int main(){ int a = 1; if (a<0) goto out; out: printf("out"); return 1; } The problem is, whatever the value a is (eg:a=-1 or a=0), the out could printed. Could anyone…
-4
votes
1 answer

How to go back to menu using case in switch case in C

How to go back to menu using case in switch case without using GOTO command. So this is the sample: while(1){ printf("1: Basic Math\n2. Intermediate Math\n3. Advance Math"); printf("Enter your choice: "); int choice; scanf("%d", &choice); …
Big. D
  • 31
  • 1
  • 7
-4
votes
4 answers

gets() function gets skipped from the second time onwards

I was playing with C and wrote this code: 1 #include 2 #define ASK_PROMPT printf("\nDo you want to continue(Y/N):"); 3 main() 4 { 5 char main[20], i; 6 start: 7 printf("Please enter your string:\n"); 8 …
-4
votes
4 answers

Transformation of C code to only use goto

I have the following C code : void BubbleSort(int a[], int array_size) { int i, j, temp; for (i = 0; i < (array_size - 1); ++i) { for (j = 0; j < array_size - 1 - i; ++j) { if (a[j] > a[j+1]) { …
yaron0
  • 57
  • 1
  • 4
-4
votes
7 answers

Elegant way to perform multiple dependent error checks in C++ without goto, and without early return?

Let's say I want to call four functions consecutively, which operate on some object of mine. If any of them fails, I want to return FAILURE without calling the others, and I want to return SUCCESS iff all of them completed successfully. Normally, I…
Adam S
  • 8,945
  • 17
  • 67
  • 103
-4
votes
1 answer

java goto command

I am a beginner to Java and I wanted to make a small fun program just for me to play with. I am familiar with the goto command but it doesn't appear to work in my Java code. can someone please direct me to a substitute. I know my code is missing a…
DrJava
  • 9
  • 3
-4
votes
1 answer

How to make my program(exe) to stop(and not exit) once an event(generation of a text file) has occured?

I am creating an executable in visual studio. My code goes like this: if(condition) goto Step 1 else goto Step 2 Step 1: code Step 2: code I want to make this in a way that if Step 1 has run then Step 2 must be skipped. Should it be…
ABX
  • 113
  • 1
  • 4
  • 12
-5
votes
1 answer

how to use goto for this for loop?

for(i=0;i<10;i++) {printf("\n %d",i);} Write a c program to print a message "Hello world" when the above for loop reaches to 5 with the help of goto keyword? Output: 1 2 3 4 Hello World 6 7 8 9 10
-5
votes
2 answers

C# goto user input

I am making an OS with Cosmos and want to use goto to go to the user input but I am getting the error No such label 'input' within the scope of the goto statement 'input' is a variable in which the user has inputted. I can understand why this is…
Ian Stegner
  • 23
  • 1
  • 1
  • 6
-5
votes
1 answer

goto vs method in finally block in c#

I am particularly aware of C# Reference and have analysed why can't i use goto statement in finally blocks but i wonder when i am trying the same thing with using methods the i am finally able to leave the finally block but according to…
Vishwa Ratna
  • 5,567
  • 5
  • 33
  • 55
-5
votes
2 answers

Using goto statement for loop

#include int main() { char choice; float x,y; start: printf("[c] Converts Celsius -> Fahrenheit\n[f] Converts Fahrenheit -> Celsius\n\n\n"); printf("Enter Choice: "); scanf("%c",&choice); if (choice!='c' ||…
-5
votes
2 answers

Referring back to code in C#

Is it was possible to run a console application in c# which has the ability to go back to a area of code? More details -- Application launch: start code runs thought code Goes back to start I know this can be done in batch with marking an area…
-5
votes
2 answers

Behaviour of goto statement

#include int main() { int i; goto l; for(i = 0; i < 5; i++) { l:printf("Hi\n"); } return 0; } The above code gives output three times Hi . I don't have any idea how it happens, please expalin it. If i…
SumS
  • 25
  • 6
-5
votes
4 answers

How to use Goto function

Can I use Goto to jump into other functions? for example void x(){ printf("hello"); } void y(){ printf("hi"); } int main(){ /*assume that all var are declared */ scanf("%d",&input); if(input == 1) goto y(); else(input == 2) goto…
PNC
  • 357
  • 1
  • 5
  • 19
-6
votes
3 answers

Why my goto command doing problems when compile?

I coded a little program for math actions, but the goto command won't compile in some cases. Please help me. Here is the code: #include #define line11 #define YorN #define End #define Start int main(void) { float…
Tom Bazak
  • 11
  • 3
1 2 3
70
71