01 · Scope
About VisuAlg
VisuAlg is an environment for writing and running algorithms in a Portuguese pseudolanguage, with its own teaching constructs. This reference brings together the syntax, functions, and teaching commands described in the author's manual for VisuAlg 3.0.5.2.
02 · Organization
Algorithm structure
An algorithm starts with the algoritmo keyword and a quoted name. Global declarations, a data file and subprograms appear before inicio; the main body ends with fimalgoritmo.
algoritmo "Welcome"
var
nome: caractere
inicio
escreva("What is your name? ")
leia(nome)
escreval("Hello, ", nome, "!")
fimalgoritmo
Braces do not delimit blocks. Structures use opening and closing keywords, such as se/fimse and enquanto/fimenquanto. The pseudolanguage uses one command per line.
For the file-reading extension, arquivo "data.txt" belongs in the declaration area before the main body. See Functions and helper commands.
03 · Writing
Names, comments and values
- Keywords and variable names are case-insensitive; by convention, write keywords in lowercase without accents, such as
entaoandlogico. - Names start with a letter and may continue with letters, digits or underscores. The reference manual sets a 30-character limit.
- Line comments start with
//and end at the line break. To comment multiple lines, start each line with its own marker. - Text literals use double quotes; decimal values use a period. Logical values are
VERDADEIROandFALSO. - One line represents one command; the pseudolanguage does not require semicolons to separate commands.
// names are case-insensitive
var
nome_do_aluno: caractere
nota: real
aprovado: logico
inicio
nota <- 8.5
aprovado <- VERDADEIRO
04 · Data
Types, variables and assignment
| Type | Use |
|---|---|
inteiro | Whole numbers. |
real | Numbers with a fractional part. |
caractere | A character or a text string in double quotes. |
logico | VERDADEIRO and FALSO values. |
Variables are declared after var, with names on the left of the colon and the type on the right. Multiple names of the same type can be separated by commas. VisuAlg has no general keyword for declaring constants; fixed values appear as literals or expressions.
algoritmo "Declarations"
var
tentativas, acertos: inteiro
media: real
nome: caractere
terminou: logico
inicio
tentativas <- 0
media <- 7.25
nome <- "Lia"
terminou <- FALSO
fimalgoritmo
The assignment operator is <-; the left side is a variable or vector element, and the right side is an expression compatible with the target type. Use = to compare equality.
05 · Expressions
Operators and precedence
| Group | Operators | Meaning |
|---|---|---|
| Assignment | <- | Stores an expression result in a variable. |
| Unary arithmetic | + - | Indicates a positive or negative sign. |
| Exponentiation | ^ | Raises a base to an exponent. |
| Arithmetic | * / \ MOD % + - | Multiplication, real division, integer division, remainder, addition and subtraction. \ performs integer division; MOD and % return the remainder. |
| Concatenation | + | Joins character-type expressions. |
| Relational | = < > <= >= <> | Equal, less than, greater than, less or equal, greater or equal and not equal. |
| Logical | nao e ou xou | Negation, conjunction, disjunction and exclusive disjunction. |
In arithmetic, ^ has the highest precedence among binary operators; *, /, \ and % come before + and -. Unary signs have higher precedence. The manual identifies nao as the highest-precedence logical operator.
The reference manual does not publish a complete precedence table for all logical and relational operators. Use parentheses to make grouping explicit instead of relying on assumed conventions.
Text comparisons are case-insensitive; for example, the manual treats "ABC" and "abc" as equal.
06 · Interaction
Input, output and formatting
leia reads values into variables in the listed order. escreva displays comma-separated expressions; escreval does the same and then starts a new line.
algoritmo "Formatting"
var
quantidade: inteiro
preco: real
inicio
escreva("Quantity: ")
leia(quantidade)
preco <- quantidade * 2.5
escreval("Total: ", preco:8:2)
fimalgoritmo
For output, value:width reserves a field of the given width; real:width:decimals also sets the number of decimal places. Text is not automatically spaced like numeric expressions, so add spaces to the text where needed.
07 · Decisions
Conditions and selection
Use se ... entao to run a block when a logical expression is true. senao is optional and fimse closes the structure; conditions can be nested.
se nota >= 7 entao
escreval("Passed")
senao
escreval("Keep practicing")
fimse
escolha evaluates an expression once and compares its value with alternatives in each caso; outrocaso defines the default case. fimescolha closes the selection.
escolha opcao
caso 1, 2
escreval("First option")
outrocaso
escreval("Another option")
fimescolha
08 · Loops
Repetition
VisuAlg documents three main loops. para counts from the starting value through the limit, including it, with a default step of 1; a negative step counts down. The control variable must be an integer.
para indice de 1 ate 5 faca
escreva(indice:3)
fimpara
enquanto quantidade > 0 faca
quantidade <- quantidade - 1
fimenquanto
repita
tentativas <- tentativas + 1
ate tentativas = 3
enquanto checks before its body and may run zero times. repita ... ate checks at the end and runs at least once. interrompa exits the current loop immediately.
An alternative form, repita ... fimrepita, has no final condition and requires interrompa to exit.
09 · Collections
Vectors and matrices
Indexed structures are declared with vetor and inclusive ranges. A vector can have one dimension and a matrix can have two. Bounds are constant integers, and the syntax gives the range for each dimension.
var
notas: vetor[1..5] de real
tabuleiro: vetor[0..2, 0..2] de caractere
inicio
notas[1] <- 9.5
tabuleiro[0, 1] <- "X"
escreval(notas[1])
escreval(tabuleiro[0, 1])
The number of elements in a dimension follows from its bounds, not from the final index alone. The first example has five positions indexed from 1 through 5; a range may also start at zero or another integer.
The VisuAlg manual documents vectors with up to two dimensions. Matrices are accessed with two comma-separated indices inside brackets.
10 · Reuse
Procedures and functions
Procedures and functions are declared after global variables and before inicio. A procedure returns no value; a function declares its return type after a colon and returns a result with retorne. Both may declare local variables in a var section.
algoritmo "Routines"
var
resultado: inteiro
funcao dobro(valor: inteiro): inteiro
inicio
retorne valor * 2
fimfuncao
procedimento somar(valor: inteiro; var total: inteiro)
inicio
total <- total + valor
fimprocedimento
inicio
resultado <- dobro(4)
somar(3, resultado)
escreval(resultado)
fimalgoritmo
Parameters separated by commas within one group share a type; different groups are separated by semicolons. Without var, a parameter is passed by value; with var, the routine may change the supplied variable. The manual supports recursion but does not allow nested routines.
Functions appear as expressions and procedures as statements. A procedure call without parameters may omit parentheses.
11 · Pseudolanguage resources
Functions and helper commands
The author's manual documents the input and output operations escreva, escreval and leia, as well as the math, trigonometric and text functions listed below. The signatures and behavior summarize the VisuAlg reference.
| Group | Names | General use |
|---|---|---|
| Math | Abs, ArcCos, ArcSen, ArcTan, Cos, CoTan, Exp, GraupRad, Int, Log, LogN, Pi, Quad, RadpGrau, RaizQ, Rand, RandI, Sen, Tan | Values, angle conversion, integer part, logarithms, trigonometry, powers and random numbers. |
| Text and characters | Asc, Carac, Caracpnum, Compr, Copia, Maiusc, Minusc, Numpcarac, Pos | Convert characters and numbers, measure and extract text, change case and locate substrings. |
Function signatures and results
Functions can be used in expressions or assigned to variables. Pi and Rand take no parameters; the other names show the number and order of their arguments.
| Group | Signature | Result |
|---|---|---|
| Math | Abs(expr), Int(expr), Quad(expr), RaizQ(expr), Exp(base, expoente), Log(expr), LogN(expr), Pi | Absolute value, integer part, square, square root, power, base-10 or natural logarithm, and the π constant. |
| Trigonometry | Cos(expr), CoTan(expr), Sen(expr), Tan(expr), ArcCos(expr), ArcSen(expr), ArcTan(expr) | Calculate trigonometric ratios and their inverse functions; input and output angles are in radians. |
| Angle conversion | GraupRad(degrees), RadpGrau(radians) | Convert degrees to radians and radians to degrees. |
| Random values | Rand, RandI(limit) | Rand returns a real from 0 inclusive to 1 exclusive; RandI returns an integer from 0 inclusive up to, but not including, the limit. |
| Text and characters | Asc(character), Carac(code), Caracpnum(string), Numpcarac(number) | Get the first character's ASCII code, convert a code to a character, text to a number, and a number to text. |
| Text and characters | Compr(string), Copia(string, start, count), Pos(substring, string) | Measure text, copy a number of characters, or find the first occurrence. Positions start at 1; Pos returns 0 when the substring is absent. |
| Text and characters | Maiusc(string), Minusc(string) | Return text in uppercase or lowercase. |
algoritmo "Function examples"
inicio
escreval(abs(2 - 9))
escreval(raizq(9))
escreval(pos("Brasil", "Brasil e Portugal"))
fimalgoritmo
Output: 7, 3 and 1, each on its own line.
VisuAlg's reference also describes commands that support teaching and the environment:
aleatorio [on]activates the generation used byleia; with no range, numbers span 0 to 100 and characters are generated as five-letter uppercase strings.aleatorio maximumsets the inclusive range from 0 to the limit;aleatorio minimum, maximumsets both inclusive bounds. Both values must be numeric constants, not expressions; if reversed, VisuAlg swaps them.aleatorio offstops generation.arquivo "path"associates reads with a text file and appears in the declaration section.timer onenables the default 500 ms delay;timer <delay>sets an integer constant in milliseconds from 0 to 10,000, clamping values outside the range. Multipletimercommands are allowed in the command section.timer offdisables the delay.pausapauses execution for inspection;debug conditionpauses when the condition is true.eco on|offcontrols whether input data is echoed to output;cronometro on|offmeasures elapsed time.limpatelaclears VisuAlg's simulated DOS screen but does not clear the main window's output panel.
12 · Example
Complete program
This example reads three grades, calculates their average and uses a function to classify the result:
algoritmo "Class average"
var
nota1, nota2, nota3, media: real
funcao aprovado(media: real): logico
inicio
retorne media >= 7
fimfuncao
inicio
escreval("Enter three grades:")
leia(nota1, nota2, nota3)
media <- (nota1 + nota2 + nota3) / 3
se aprovado(media) entao
escreval("Passed with an average of ", media:5:2)
senao
escreval("Keep studying: average ", media:5:2)
fimse
fimalgoritmo
13 · Reading tips
Common mistakes and how to avoid them
- Using the wrong assignment symbol: in VisuAlg,
<-assigns a value;=compares values in a condition. - Leaving a block open: each structure must end with its matching marker, such as
fimse,fimpara,fimfuncaoorfimalgoritmo. - Confusing an index with a count: vectors use their declared bounds;
Copia(string, start, count)counts positions from 1 and its third argument is the number of characters to copy. - Expecting zero-based results from
Pos: positions start at 1, and result0means the substring was not found. - Assuming the random limit is included:
RandI(limit)returns values from zero up to, but not including, the limit. Thealeatoriocommand uses inclusive ranges for input data. - Treating environment commands as functions:
aleatorio,timeranddebugare commands described by VisuAlg, not calls that return values.
= (comparison) from <- (assignment).14 · Further reading
VisuAlg references
- The pseudolanguage manual distributed by VisuAlg's author, covering syntax, types, operators, commands, routines and teaching extensions; the command reference also details
aleatorioandlimpatela. - The numeric and text function catalog, with signatures and example results.
- A copy of the manual in a university repository.
The manual presents VisuAlg syntax and teaching features. Consult the references to confirm function signatures and command behavior.