ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
begin_repeat.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSÌ COM'È", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#include "../../ugbc.h"
36
37/****************************************************************************
38 * CODE SECTION
39 ****************************************************************************/
40
49/* <usermanual>
50@keyword REPEAT...UNTIL
51
52@english
53
54The '''REPEAT...UNTIL'' command will repeatedly execute a block of code until a certain
55condition is met. In essence, it creates a loop that continues to repeat until a specific
56exit condition is met.
57
58When you don't know exactly how many times you want to repeat a block of code, but you
59want to continue until a certain condition is met, this is the best command to use.
60For example, to repeatedly prompt the user for input until they enter it correctly.
61Another usage is to perform calculations that require multiple iterations, such as
62finding the square root of a number using the Newton-Raphson method.
63
64Make sure the condition inside ''UNTIL'' can become true at some point, otherwise your
65program may end up in an infinite loop. If you need to execute a loop a large number
66of times, consider optimizing your code to improve performance.
67
68@italian
69
70Il comando '''REPEAT...UNTIL'' eseguirà ripetutamente un blocco di codice finché
71non viene soddisfatta una determinata condizione. In sostanza, crea un ciclo che
72continua a ripetersi finché non viene soddisfatta una specifica condizione di uscita.
73
74Quando non sai esattamente quante volte vuoi ripetere un blocco di codice, ma vuoi
75continuare finché non viene soddisfatta una determinata condizione, questo è il
76comando migliore da usare.
77
78Ad esempio, per chiedere ripetutamente all'utente di immettere un input finché non
79lo inserisce correttamente. Un altro utilizzo è per eseguire calcoli che richiedono
80più iterazioni, come trovare la radice quadrata di un numero utilizzando il metodo
81Newton-Raphson.
82
83Assicurati che la condizione all'interno di ''UNTIL'' possa diventare vera a un
84certo punto, altrimenti il ​​tuo programma potrebbe finire in un ciclo infinito.
85Se hai bisogno di eseguire un ciclo un gran numero di volte, prendi in considerazione
86l'ottimizzazione del tuo codice per migliorare le prestazioni.
87
88@syntax REPEAT
89@syntax ...
90@syntax UNTIL expression
91
92@example REPEAT
93@example score = score + 1
94@example UNTIL alive
95
96@usedInExample control_loops_05.bas
97
98@seeAlso DO...LOOP
99@seeAlso WHILE...WEND
100@seeAlso FOR...NEXT
101
102</usermanual> */
103void begin_repeat( Environment * _environment ) {
104
106
107 Loop * loop = malloc( sizeof( Loop ) );
108 loop->label = strdup( label );
109 loop->type = LT_REPEAT;
110 loop->next = _environment->loops;
111 _environment->loops = loop;
112
113 unsigned char newLabel[MAX_TEMPORARY_STORAGE]; sprintf(newLabel, "%sbis", loop->label );
114
115 if ( _environment->procedureName && _environment->protothread && ! _environment->protothreadForbid ) {
116 yield( _environment );
117 }
118
119 cpu_label( _environment, loop->label );
120
121}
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void begin_repeat(Environment *_environment)
Emit ASM code for REPEAT ....
int protothread
Definition ugbc.h:2830
char * procedureName
Definition ugbc.h:2775
int protothreadForbid
Definition ugbc.h:2845
Loop * loops
Definition ugbc.h:2669
void * malloc(YYSIZE_T)
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
void loop(Environment *_environment, char *_label)
struct _Environment Environment
Structure of compilation environment.
@ LT_REPEAT
Definition ugbc.h:1393
struct _Loop Loop
Structure of a single loop.
#define MAKE_LABEL
Definition ugbc.h:3351
void yield(Environment *_environment)
Emit code for YIELD.
Definition yield.c:63