for loop

for loop - Сообщения

#1 Опубликовано: 16.11.2013 03:40:08
alberich

alberich

0 сообщений из 2 понравились пользователям.

Группа: User

Hello,

I am new to smath and may probably have missed something relating to the syntax.
However, the following result surprised me and I am quite curious why I get this result.
remark: I use smath under linux (debian).

al
for loop.jpg
#2 Опубликовано: 16.11.2013 05:34:04
Martin Kraska

Martin Kraska

1222 сообщений из 2150 понравились пользователям.

Группа: Moderator

Wrote

Hello,

I am new to smath and may probably have missed something relating to the syntax.
However, the following result surprised me and I am quite curious why I get this result.
remark: I use smath under linux (debian).

al


Interesting question. I never used lists (systems) to make instruction blocks. As your example demonstrates, the entries in a list (as well as in matrices) are evaluated in reverse sequence.

In the first loop iteration, z is not defined and stored symbolically in b[1;1, then z is set to 1
After leaving the loop, z has the value 9, which is substituted for z when you evaluate b. You see that if you hover with the mouse over the loop statement.

If you reverse the entries, you get the expected behaviour.

Normally you are supposed to use the line() function for instruction blocks. The elements are evaluated top-down and the block has the result of the last statement as return value.

EDIT:

It seems that there are severe operator spacing problems under linux. Between variable and array index there should be more space in order to distinguish such indices from text indices. Also, the := in the loop header look like = because the : is printed over the preceeding operator. You might experiment with the dpi settings.
line.sm (7 КиБ) скачан 188 раз(а).
Martin Kraska Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
#3 Опубликовано: 17.11.2013 03:36:31
alberich

alberich

0 сообщений из 2 понравились пользователям.

Группа: User

Thank you for the quick reply.
al
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений