Error: ...initial value in for loop must be numeric or character
...final value in for loop must be numeric or character
...increment of for loop must be numeric
...increment when looping over characters must be an integer
...final value in for loop must have same type as initial
|
Description
|
|
The error messages related to loops indicate that elements must be numeric, character, or integer.
|
|
Examples
|
|
Intial value
>
|
|
If the final value is numeric, ensure that the initial value is numeric, for example, 1.
>
|
|
| (2.1) |
>
|
|
If the final value is a character, ensure that initial value is also a character.
>
|
|
| (2.2) |
Final value
>
|
|
| (2.3) |
>
|
|
Use the type command to verify whether the value is numeric or character.
>
|
|
| (2.4) |
>
|
|
| (2.5) |
Ensure that the final value is numeric or character.
>
|
|
| (2.6) |
Increment of for loop
>
|
|
>
|
|
| (2.7) |
>
|
|
| (2.8) |
Use evalf to evalute the square root of 2, therefore making the increment numeric.
>
|
|
| (2.9) |
Increment when looping over characters
>
|
|
>
|
|
| (2.10) |
>
|
|
>
|
|
| (2.11) |
|
|
Download Help Document
Was this information helpful?