answersLogoWhite

0

How do you use gotoxy in for loop?

Updated: 8/11/2023
User Avatar

Wiki User

10y ago

Best Answer

Avoid using goto -- it's a sign of bad programming. apart from the risk of jumping over vital memory cleanup code, your code will be that much harder to follow.

Replace all the gotos with function calls or place non-duplicate code inline within the loop itself. To conditionally exit a loop prematurely, use break, not goto. Place the break immediately after the function call or immediately after the inline code.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you use gotoxy in for loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why to use gotoxy function in c plus plus?

to locate coordinates ..


Tell more about gotoxy statemant and more of its use in c and c plus plus?

gotoXY function is defined in conio.h, it places the cursor to the given position. If you have any question about it, use the built-in help.


Function of GoTOXY?

Gotoxy is used to move the cursor on the monitor screen. Gotoxy follows a certain programming code to put the cursor in the desired position.


What is syntax in gotoxy?

AnswerGotoXY is a function or procedure that positions the cursor at (X,Y), X in horizontal, Y in vertical direction relative to the origin of the current window. The origin is located at (1,1), the upper-left corner of the window. AnswerDescription This shows how to use the gotoxy function in C to move the text cursor to a different location on the screen Code#include#includeint main(void){int i;printf("This is the first line.\n");gotoxy(10,4);printf("This is the second line.\n");gotoxy(20,8);printf("And this is line 3.\n");return 0;}


Example of ATM programing by turbo c?

#include<stdio.h> #include<conio.h> #include<graphics.h> #include<stdlib.h> #define pf printf #define s scanf int gd=DETECT, gm, pa, o, b; int i; int x, y, i,ch,c; int c, m, p, qn, cm, mp, cp, cmp, n, k, p1, g,qcm,qmp,qcp,qc,qm,qp; void main() { initgraph(&gd,&gm," "); cleardevice(); line(0,0,639,0); line(0,0,0,479); line(639,0,639,479); line(639,479,0,479); line(589,479,0,479); randomize(); for(i=0;i<640;i++) { setcolor(i); x=rand()%639; y=rand()%480; putpixel (x,y,i); { setcolor(RED); settextstyle(3,0,5); outtextxy(60,100, "PROJECT IN DISCRETE"); setcolor(RED); settextstyle(3,0,5); outtextxy(80,135, "MATHEMATICS"); setcolor(i); settextstyle(2,0,5); outtextxy(120,192,"SUBMITTED BY :"); setcolor(i); settextstyle(2,0,5); outtextxy(120,202,"Cabrera"); setcolor(i); settextstyle(2,0,5); outtextxy(120,214,"Gaspar"); setcolor(i); settextstyle(2,0,5); outtextxy(120,226,"Molina"); setcolor(i); settextstyle(2,0,5); outtextxy(120,238,"Viray"); } setcolor(i); settextstyle(2,0,5); outtextxy(400,350,"U P L O A D i N G..."); setcolor(WHITE); outtextxy(i,378,"="); outtextxy(i,406,"="); setcolor(WHITE); circle(i,400,10); delay(1); } cleardevice(); gotoxy(10,7); pf("Enter 1 for V E N N D I A G R A M "); gotoxy(10,8); pf("Enter 2 for S E T N O T A T I O N"); gotoxy(10,10); printf("Input: "); s("%d",&pa); cleardevice(); { if(pa==1) { { line(0,0,639,0); line(0,0,0,479); line(639,0,639,479); line(639,479,0,479); line(589,479,0,479); randomize(); for(i=0;i<640;i++) { setcolor(i); x=rand()%639; y=rand()%480; putpixel (x,y,i); { setcolor(i); settextstyle(9,0,5); outtextxy(60,100, "V E N N"); setcolor(i); settextstyle(9,0,5); outtextxy(80,165, "D I A G R A M"); } setcolor(i); settextstyle(2,0,5); outtextxy(400,350,"U P L O A D i N G..."); setcolor(YELLOW); outtextxy(i,378,"="); outtextxy(i,406,"="); setcolor(WHITE); circle(i,400,10); delay(1); } sleep(1); cleardevice(); } gotoxy(10,7); pf("Enter 1 if the Outside is missing. 3 Circle. "); gotoxy(10,8); pf("Enter 2 if the Total is missing. 3 Circle."); gotoxy(10,11); printf("Choice : "); s("%d",&p1); for(g=1;g<=8;g++) { if(p1==1) { cleardevice(); gotoxy(32,8); pf("Input the Values for the following variables:"); gotoxy(32,11); pf("X:"); gotoxy(32,12); pf("Y:"); gotoxy(32,13); pf("Z:"); gotoxy(32,14); pf("XY:"); gotoxy(32,15); pf("XZ:"); gotoxy(32,16); pf("YZ:"); gotoxy(32,17); pf("XYZ:"); gotoxy(32,18); pf("Outside:"); gotoxy(32,19); pf("Total Number:"); { if(g==1){gotoxy(42,18);pf("----");gotoxy(42,11);s("%d",&c);} if(g==2){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);s("%d",&m);} if(g==3){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);s("%d",&p);} if(g==4){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);scanf("%d",&cm);} if(g==5){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);s("%d",&cp);} if(g==6){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);pf("%d",cp);gotoxy(42,16);s("%d",&mp);} if(g==7){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);pf("%d",cp);gotoxy(42,16);pf("%d",mp);gotoxy(42,17);s("%d",&cmp);} if(g==8){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);pf("%d",cp);gotoxy(42,16);pf("%d",mp);gotoxy(42,17);pf("%d",cmp);gotoxy(50,19);s("%d",&k);} cleardevice(); }} { qcm=cm-cmp; qmp=mp-cmp; qcp=cp-cmp; qc=c-(qcp+cmp+qcm); qm=m-(qcm+cmp+qmp); qp=p-(qcp+cmp+qmp); qn=k-(cmp+qcp+qcm+qmp+qc+qm+qp); } cleardevice(); setcolor(RED); rectangle(600,450,40,40); setcolor(YELLOW); circle(250,200,125); setcolor(GREEN); circle(375,200,125); setcolor(BLUE); circle(313,300,125); gotoxy(39,15); printf("%d",cmp); gotoxy(30,4); printf("X"); gotoxy(49,4); printf("Y"); gotoxy(23,12); printf("%d",qc); gotoxy(55,12); printf("%d",qm); gotoxy(39,23); printf("%d",qp); gotoxy(39,9); printf("%d",qcm); gotoxy(30,18); printf("%d",qcp); gotoxy(49,18); printf("%d",qmp); gotoxy(63,25); printf("%d",qn); gotoxy(39,27); setcolor(WHITE); outtextxy(310,435,"Z"); } for(g=1;g<=8;g++) { if(p1==2) {cleardevice(); gotoxy(32,8); pf("Input the Values for the following variables:"); gotoxy(32,11); pf("X:"); gotoxy(32,12); pf("Y:"); gotoxy(32,13); pf("Z:"); gotoxy(32,14); pf("XY:"); gotoxy(32,15); pf("XZ:"); gotoxy(32,16); pf("YZ:"); gotoxy(32,17); pf("XYZ:"); gotoxy(32,18); pf("Outside:"); gotoxy(32,19); pf("Total Number:"); { if(g==1){gotoxy(42,19);pf("----");gotoxy(42,11);s("%d",&c);} if(g==2){gotoxy(42,19);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);s("%d",&m);} if(g==3){gotoxy(42,19);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);s("%d",&p);} if(g==4){gotoxy(42,19);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);scanf("%d",&cm);} if(g==5){gotoxy(42,19);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);s("%d",&cp);} if(g==6){gotoxy(42,19);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);pf("%d",cp);gotoxy(42,16);s("%d",&mp);} if(g==7){gotoxy(42,19);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);pf("%d",cp);gotoxy(42,16);pf("%d",mp);gotoxy(42,17);pf("%d",cmp);gotoxy(42,18);s("%d",&n);} cleardevice(); }} { qcm=cm-cmp; qmp=mp-cmp; qcp=cp-cmp; qc=c-(qcp+cmp+qcm); qm=m-(qcm+cmp+qmp); qp=p-(qcp+cmp+qmp); qn=k-(cmp+qcp+qcm+qmp+qc+qm+qp); } cleardevice(); setcolor(RED); rectangle(600,450,40,40); setcolor(YELLOW); circle(250,200,125); setcolor(GREEN); circle(375,200,125); setcolor(BLUE); circle(313,300,125); gotoxy(39,15); printf("%d",cmp); gotoxy(30,4); printf("X"); gotoxy(49,4); printf("Y"); gotoxy(23,12); printf("%d",qc); gotoxy(55,12); printf("%d",qm); gotoxy(39,23); printf("%d",qp); gotoxy(39,9); printf("%d",qcm); gotoxy(30,18); printf("%d",qcp); gotoxy(49,18); printf("%d",qmp); gotoxy(63,25); printf("%d",qn); gotoxy(39,27); setcolor(WHITE); outtextxy(310,435,"Z"); } } getche(); } { if(pa==2) { { line(0,0,639,0); line(0,0,0,479); line(639,0,639,479); line(639,479,0,479); line(589,479,0,479); randomize(); for(i=0;i<640;i++) { setcolor(i); x=rand()%639; y=rand()%480; putpixel (x,y,i); { setcolor(i); settextstyle(9,0,5); outtextxy(60,100, "S E T"); setcolor(i); settextstyle(9,0,5); outtextxy(50,165, "N O T A T I O N"); } setcolor(i); settextstyle(2,0,5); outtextxy(400,350,"U P L O A D i N G..."); setcolor(YELLOW); outtextxy(i,378,"="); outtextxy(i,406,"="); setcolor(WHITE); circle(i,400,10); delay(1); } sleep(1); cleardevice(); } printf("ogi"); getche(); } } cleardevice(); gotoxy(10,10); printf("--END--"); getche(); }

Related questions

How do you write a program in c for making swastik fig by using for loops and space loop?

Best Answer - Chosen by Voters#include #includemain(){int i;clrscr();for(i=10;i


Which header file is used for gotoxy function in turbo c plus plus?

It's in conio.h, but don't use gotoxy. Use SetCursorPosition() instead.


What is gotoxy in turbo c?

A function, defined in conio.h. Use the help.


Why to use gotoxy function in c plus plus?

to locate coordinates ..


Tell more about gotoxy statemant and more of its use in c and c plus plus?

gotoXY function is defined in conio.h, it places the cursor to the given position. If you have any question about it, use the built-in help.


Function of GoTOXY?

Gotoxy is used to move the cursor on the monitor screen. Gotoxy follows a certain programming code to put the cursor in the desired position.


What is syntax in gotoxy?

AnswerGotoXY is a function or procedure that positions the cursor at (X,Y), X in horizontal, Y in vertical direction relative to the origin of the current window. The origin is located at (1,1), the upper-left corner of the window. AnswerDescription This shows how to use the gotoxy function in C to move the text cursor to a different location on the screen Code#include#includeint main(void){int i;printf("This is the first line.\n");gotoxy(10,4);printf("This is the second line.\n");gotoxy(20,8);printf("And this is line 3.\n");return 0;}


Example of ATM programing by turbo c?

#include<stdio.h> #include<conio.h> #include<graphics.h> #include<stdlib.h> #define pf printf #define s scanf int gd=DETECT, gm, pa, o, b; int i; int x, y, i,ch,c; int c, m, p, qn, cm, mp, cp, cmp, n, k, p1, g,qcm,qmp,qcp,qc,qm,qp; void main() { initgraph(&gd,&gm," "); cleardevice(); line(0,0,639,0); line(0,0,0,479); line(639,0,639,479); line(639,479,0,479); line(589,479,0,479); randomize(); for(i=0;i<640;i++) { setcolor(i); x=rand()%639; y=rand()%480; putpixel (x,y,i); { setcolor(RED); settextstyle(3,0,5); outtextxy(60,100, "PROJECT IN DISCRETE"); setcolor(RED); settextstyle(3,0,5); outtextxy(80,135, "MATHEMATICS"); setcolor(i); settextstyle(2,0,5); outtextxy(120,192,"SUBMITTED BY :"); setcolor(i); settextstyle(2,0,5); outtextxy(120,202,"Cabrera"); setcolor(i); settextstyle(2,0,5); outtextxy(120,214,"Gaspar"); setcolor(i); settextstyle(2,0,5); outtextxy(120,226,"Molina"); setcolor(i); settextstyle(2,0,5); outtextxy(120,238,"Viray"); } setcolor(i); settextstyle(2,0,5); outtextxy(400,350,"U P L O A D i N G..."); setcolor(WHITE); outtextxy(i,378,"="); outtextxy(i,406,"="); setcolor(WHITE); circle(i,400,10); delay(1); } cleardevice(); gotoxy(10,7); pf("Enter 1 for V E N N D I A G R A M "); gotoxy(10,8); pf("Enter 2 for S E T N O T A T I O N"); gotoxy(10,10); printf("Input: "); s("%d",&pa); cleardevice(); { if(pa==1) { { line(0,0,639,0); line(0,0,0,479); line(639,0,639,479); line(639,479,0,479); line(589,479,0,479); randomize(); for(i=0;i<640;i++) { setcolor(i); x=rand()%639; y=rand()%480; putpixel (x,y,i); { setcolor(i); settextstyle(9,0,5); outtextxy(60,100, "V E N N"); setcolor(i); settextstyle(9,0,5); outtextxy(80,165, "D I A G R A M"); } setcolor(i); settextstyle(2,0,5); outtextxy(400,350,"U P L O A D i N G..."); setcolor(YELLOW); outtextxy(i,378,"="); outtextxy(i,406,"="); setcolor(WHITE); circle(i,400,10); delay(1); } sleep(1); cleardevice(); } gotoxy(10,7); pf("Enter 1 if the Outside is missing. 3 Circle. "); gotoxy(10,8); pf("Enter 2 if the Total is missing. 3 Circle."); gotoxy(10,11); printf("Choice : "); s("%d",&p1); for(g=1;g<=8;g++) { if(p1==1) { cleardevice(); gotoxy(32,8); pf("Input the Values for the following variables:"); gotoxy(32,11); pf("X:"); gotoxy(32,12); pf("Y:"); gotoxy(32,13); pf("Z:"); gotoxy(32,14); pf("XY:"); gotoxy(32,15); pf("XZ:"); gotoxy(32,16); pf("YZ:"); gotoxy(32,17); pf("XYZ:"); gotoxy(32,18); pf("Outside:"); gotoxy(32,19); pf("Total Number:"); { if(g==1){gotoxy(42,18);pf("----");gotoxy(42,11);s("%d",&c);} if(g==2){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);s("%d",&m);} if(g==3){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);s("%d",&p);} if(g==4){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);scanf("%d",&cm);} if(g==5){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);s("%d",&cp);} if(g==6){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);pf("%d",cp);gotoxy(42,16);s("%d",&mp);} if(g==7){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);pf("%d",cp);gotoxy(42,16);pf("%d",mp);gotoxy(42,17);s("%d",&cmp);} if(g==8){gotoxy(42,18);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);pf("%d",cp);gotoxy(42,16);pf("%d",mp);gotoxy(42,17);pf("%d",cmp);gotoxy(50,19);s("%d",&k);} cleardevice(); }} { qcm=cm-cmp; qmp=mp-cmp; qcp=cp-cmp; qc=c-(qcp+cmp+qcm); qm=m-(qcm+cmp+qmp); qp=p-(qcp+cmp+qmp); qn=k-(cmp+qcp+qcm+qmp+qc+qm+qp); } cleardevice(); setcolor(RED); rectangle(600,450,40,40); setcolor(YELLOW); circle(250,200,125); setcolor(GREEN); circle(375,200,125); setcolor(BLUE); circle(313,300,125); gotoxy(39,15); printf("%d",cmp); gotoxy(30,4); printf("X"); gotoxy(49,4); printf("Y"); gotoxy(23,12); printf("%d",qc); gotoxy(55,12); printf("%d",qm); gotoxy(39,23); printf("%d",qp); gotoxy(39,9); printf("%d",qcm); gotoxy(30,18); printf("%d",qcp); gotoxy(49,18); printf("%d",qmp); gotoxy(63,25); printf("%d",qn); gotoxy(39,27); setcolor(WHITE); outtextxy(310,435,"Z"); } for(g=1;g<=8;g++) { if(p1==2) {cleardevice(); gotoxy(32,8); pf("Input the Values for the following variables:"); gotoxy(32,11); pf("X:"); gotoxy(32,12); pf("Y:"); gotoxy(32,13); pf("Z:"); gotoxy(32,14); pf("XY:"); gotoxy(32,15); pf("XZ:"); gotoxy(32,16); pf("YZ:"); gotoxy(32,17); pf("XYZ:"); gotoxy(32,18); pf("Outside:"); gotoxy(32,19); pf("Total Number:"); { if(g==1){gotoxy(42,19);pf("----");gotoxy(42,11);s("%d",&c);} if(g==2){gotoxy(42,19);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);s("%d",&m);} if(g==3){gotoxy(42,19);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);s("%d",&p);} if(g==4){gotoxy(42,19);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);scanf("%d",&cm);} if(g==5){gotoxy(42,19);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);s("%d",&cp);} if(g==6){gotoxy(42,19);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);pf("%d",cp);gotoxy(42,16);s("%d",&mp);} if(g==7){gotoxy(42,19);pf("----");gotoxy(42,11);pf("%d",c);gotoxy(42,12);pf("%d",m);gotoxy(42,13);pf("%d",p);gotoxy(42,14);pf("%d",cm);gotoxy(42,15);pf("%d",cp);gotoxy(42,16);pf("%d",mp);gotoxy(42,17);pf("%d",cmp);gotoxy(42,18);s("%d",&n);} cleardevice(); }} { qcm=cm-cmp; qmp=mp-cmp; qcp=cp-cmp; qc=c-(qcp+cmp+qcm); qm=m-(qcm+cmp+qmp); qp=p-(qcp+cmp+qmp); qn=k-(cmp+qcp+qcm+qmp+qc+qm+qp); } cleardevice(); setcolor(RED); rectangle(600,450,40,40); setcolor(YELLOW); circle(250,200,125); setcolor(GREEN); circle(375,200,125); setcolor(BLUE); circle(313,300,125); gotoxy(39,15); printf("%d",cmp); gotoxy(30,4); printf("X"); gotoxy(49,4); printf("Y"); gotoxy(23,12); printf("%d",qc); gotoxy(55,12); printf("%d",qm); gotoxy(39,23); printf("%d",qp); gotoxy(39,9); printf("%d",qcm); gotoxy(30,18); printf("%d",qcp); gotoxy(49,18); printf("%d",qmp); gotoxy(63,25); printf("%d",qn); gotoxy(39,27); setcolor(WHITE); outtextxy(310,435,"Z"); } } getche(); } { if(pa==2) { { line(0,0,639,0); line(0,0,0,479); line(639,0,639,479); line(639,479,0,479); line(589,479,0,479); randomize(); for(i=0;i<640;i++) { setcolor(i); x=rand()%639; y=rand()%480; putpixel (x,y,i); { setcolor(i); settextstyle(9,0,5); outtextxy(60,100, "S E T"); setcolor(i); settextstyle(9,0,5); outtextxy(50,165, "N O T A T I O N"); } setcolor(i); settextstyle(2,0,5); outtextxy(400,350,"U P L O A D i N G..."); setcolor(YELLOW); outtextxy(i,378,"="); outtextxy(i,406,"="); setcolor(WHITE); circle(i,400,10); delay(1); } sleep(1); cleardevice(); } printf("ogi"); getche(); } } cleardevice(); gotoxy(10,10); printf("--END--"); getche(); }


How do you write a program using the gotoxy statement and print function to display letters of the alphabet on the computer screen?

There is no gotoxy statement in C.


How do you declare gotoxy?

You don't declare library functions. Simply include conio.h. For details use the built-in help.


For loop -uses?

You can use a for loop whenever you can use a while loop; it's the same.


How do you set the cursor in turbo c?

gotoXY from conio.h