First of all ... Documentation . Thanks @Krismorte by
Understanding what happened
The error is in the use of for
. The for
consists of 3 (optional) fields: initial assignment, comparison, increment. In the first field, you did not perform any assignment operation, just put the variable name.
This applies to most languages that share the syntax of the traditional for
of C. Some languages have syntax for for-each
(another loop expression). Other languages allow the first field to also be declared variable, but C-ANSI89 does not.
Okay, but how to fix?
Thanks to @Isac for realizing that the value started was from reading the text, not 0
You could start the value int deQuantidade = Convert.ToInt32(txtDe.Text)
in the first field of for
:
for (int deQuantidade = Convert.ToInt32(txtDe.Text); deQuantidade < ateQuantidade; deQuantidade++) {
// ...
This field, by the way, can be used for multiple initializations (separated by commas ,
):
for (int deQuantidade = Convert.ToInt32(txtDe.Text), int ateQuantidade = Convert.ToInt32(txtAte.Text); deQuantidade < ateQuantidade; deQuantidade++) {
// ...
Or, by maintaining the statement structure prior to the loop (but not initializing the variable):
int deQuantidade;
// ...
for (deQuantidade = Convert.ToInt32(txtDe.Text); deQuantidade < ateQuantidade; deQuantidade++) {
// ...
Or, keeping the boot structure before the loop:
int deQuantidade = 0;
// ...
deQuantidade = Convert.ToInt32(txtDe.Text);
// ...
for (; deQuantidade < ateQuantidade; deQuantidade++) {
// ...