Home » Archimedes archive » Acorn User » AU 1995-04.adf » !C_C » c/goto
c/goto
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn User » AU 1995-04.adf » !C_C |
Filename: | c/goto |
Read OK: | ✔ |
File size: | 0362 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
/* Demonstrating the use of the (dreaded) GOTO */ /* Acorn User 'C for yourself' demonstration C program - April 1995 */ #include <stdio.h> main() { int x = 0, y = 0, z = 0; printf("This program makes extensive use of GOTO...\n"); printf("Can you follow its program listing?\n"); label1: x++; if (x > 5) goto label3; label2: goto l4; label3: printf("x = %d, y = %d\n",x,y); y++; x/=2; if (y > x) { goto label1; } else { goto l5; } anotherlabel: printf("Have you noticed how this label never gets called?\n"); l4: z = x % 2; if (z = 0) goto label3; x+=5; l5: if (y > 10) goto end; goto label1; end: printf("Thank goodness that's over...\n"); }
00000000 2f 2a 20 44 65 6d 6f 6e 73 74 72 61 74 69 6e 67 |/* Demonstrating| 00000010 20 74 68 65 20 75 73 65 20 6f 66 20 74 68 65 20 | the use of the | 00000020 28 64 72 65 61 64 65 64 29 20 47 4f 54 4f 20 2a |(dreaded) GOTO *| 00000030 2f 0a 2f 2a 20 41 63 6f 72 6e 20 55 73 65 72 20 |/./* Acorn User | 00000040 27 43 20 66 6f 72 20 79 6f 75 72 73 65 6c 66 27 |'C for yourself'| 00000050 20 64 65 6d 6f 6e 73 74 72 61 74 69 6f 6e 20 43 | demonstration C| 00000060 20 70 72 6f 67 72 61 6d 20 2d 20 41 70 72 69 6c | program - April| 00000070 20 31 39 39 35 20 2a 2f 0a 0a 23 69 6e 63 6c 75 | 1995 */..#inclu| 00000080 64 65 20 20 20 20 3c 73 74 64 69 6f 2e 68 3e 0a |de <stdio.h>.| 00000090 0a 6d 61 69 6e 28 29 0a 7b 0a 20 20 20 20 69 6e |.main().{. in| 000000a0 74 20 78 20 3d 20 30 2c 20 79 20 3d 20 30 2c 20 |t x = 0, y = 0, | 000000b0 7a 20 3d 20 30 3b 0a 20 20 20 20 70 72 69 6e 74 |z = 0;. print| 000000c0 66 28 22 54 68 69 73 20 70 72 6f 67 72 61 6d 20 |f("This program | 000000d0 6d 61 6b 65 73 20 65 78 74 65 6e 73 69 76 65 20 |makes extensive | 000000e0 75 73 65 20 6f 66 20 47 4f 54 4f 2e 2e 2e 5c 6e |use of GOTO...\n| 000000f0 22 29 3b 0a 20 20 20 20 70 72 69 6e 74 66 28 22 |");. printf("| 00000100 43 61 6e 20 79 6f 75 20 66 6f 6c 6c 6f 77 20 69 |Can you follow i| 00000110 74 73 20 70 72 6f 67 72 61 6d 20 6c 69 73 74 69 |ts program listi| 00000120 6e 67 3f 5c 6e 22 29 3b 0a 0a 20 20 20 20 6c 61 |ng?\n");.. la| 00000130 62 65 6c 31 3a 0a 20 20 20 20 20 20 20 20 78 2b |bel1:. x+| 00000140 2b 3b 0a 20 20 20 20 20 20 20 20 69 66 20 28 78 |+;. if (x| 00000150 20 3e 20 35 29 20 67 6f 74 6f 20 6c 61 62 65 6c | > 5) goto label| 00000160 33 3b 0a 20 20 20 20 6c 61 62 65 6c 32 3a 0a 20 |3;. label2:. | 00000170 20 20 20 20 20 20 20 67 6f 74 6f 20 6c 34 3b 0a | goto l4;.| 00000180 20 20 20 20 6c 61 62 65 6c 33 3a 20 20 20 20 20 | label3: | 00000190 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 | | 000001a0 20 20 20 20 0a 20 20 20 20 20 20 20 20 70 72 69 | . pri| 000001b0 6e 74 66 28 22 78 20 3d 20 25 64 2c 20 79 20 3d |ntf("x = %d, y =| 000001c0 20 25 64 5c 6e 22 2c 78 2c 79 29 3b 0a 20 20 20 | %d\n",x,y);. | 000001d0 20 20 20 20 20 79 2b 2b 3b 0a 20 20 20 20 20 20 | y++;. | 000001e0 20 20 78 2f 3d 32 3b 0a 20 20 20 20 20 20 20 20 | x/=2;. | 000001f0 69 66 20 28 79 20 3e 20 78 29 20 7b 0a 20 20 20 |if (y > x) {. | 00000200 20 20 20 20 20 20 20 20 20 67 6f 74 6f 20 6c 61 | goto la| 00000210 62 65 6c 31 3b 0a 20 20 20 20 20 20 20 20 7d 20 |bel1;. } | 00000220 65 6c 73 65 20 7b 0a 20 20 20 20 20 20 20 20 20 |else {. | 00000230 20 20 20 67 6f 74 6f 20 6c 35 3b 0a 20 20 20 20 | goto l5;. | 00000240 20 20 20 20 7d 0a 20 20 20 20 61 6e 6f 74 68 65 | }. anothe| 00000250 72 6c 61 62 65 6c 3a 0a 20 20 20 20 20 20 20 20 |rlabel:. | 00000260 70 72 69 6e 74 66 28 22 48 61 76 65 20 79 6f 75 |printf("Have you| 00000270 20 6e 6f 74 69 63 65 64 20 68 6f 77 20 74 68 69 | noticed how thi| 00000280 73 20 6c 61 62 65 6c 20 6e 65 76 65 72 20 67 65 |s label never ge| 00000290 74 73 20 63 61 6c 6c 65 64 3f 5c 6e 22 29 3b 0a |ts called?\n");.| 000002a0 20 20 20 20 6c 34 3a 0a 20 20 20 20 20 20 20 20 | l4:. | 000002b0 7a 20 3d 20 78 20 25 20 32 3b 0a 20 20 20 20 20 |z = x % 2;. | 000002c0 20 20 20 69 66 20 28 7a 20 3d 20 30 29 20 67 6f | if (z = 0) go| 000002d0 74 6f 20 6c 61 62 65 6c 33 3b 0a 20 20 20 20 20 |to label3;. | 000002e0 20 20 20 78 2b 3d 35 3b 0a 20 20 20 20 6c 35 3a | x+=5;. l5:| 000002f0 0a 20 20 20 20 20 20 20 20 69 66 20 28 79 20 3e |. if (y >| 00000300 20 31 30 29 20 67 6f 74 6f 20 65 6e 64 3b 0a 20 | 10) goto end;. | 00000310 20 20 20 20 20 20 20 67 6f 74 6f 20 6c 61 62 65 | goto labe| 00000320 6c 31 3b 0a 20 20 20 20 65 6e 64 3a 0a 20 20 20 |l1;. end:. | 00000330 20 20 20 20 20 70 72 69 6e 74 66 28 22 54 68 61 | printf("Tha| 00000340 6e 6b 20 67 6f 6f 64 6e 65 73 73 20 74 68 61 74 |nk goodness that| 00000350 27 73 20 6f 76 65 72 2e 2e 2e 5c 6e 22 29 3b 0a |'s over...\n");.| 00000360 0a 7d |.}| 00000362