for loop

for loop - 消息

#1 已发布: 2013/11/16 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 已发布: 2013/11/16 05:34:04
Martin Kraska

Martin Kraska

1,362个赞,共2,276个帖子。

组: 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.74 KiB)已下载 1554 次。
Technische Mechanik mit SMath Studio: https://link.springer.com/book/10.1007/978-3-658-50592-9
#3 已发布: 2013/11/17 03:36:31
alberich

alberich

0个赞,共2个帖子。

组: User

Thank you for the quick reply.
al
  • 有新帖
  • 无新帖