How to make a reverse for loop

3 views
Skip to first unread message

Razetime

unread,
Oct 23, 2022, 7:23:27 AM10/23/22
to felix
I am trying to make a reverse for loop, aka the equivalent of:

for(int i=n; i>=0;i--)

I have tried these:

for j in n..0 // doesn't work

var jr = range(0,n);
jr = jr.rev;
for j in jr do // too many lines

Am I missing something, or is this the simplest way to do so?

John Skaller

unread,
Oct 25, 2022, 8:36:23 PM10/25/22
to felix


> On 23 Oct 2022, at 22:23, Razetime <rraghu...@gmail.com> wrote:
>
> I am trying to make a reverse for loop, aka the equivalent of:
>
> for(int i=n; i>=0;i--)

var i : int;
for(i=n; i>=0; —i;) ….


Notice (a) in this form you have to pre-declare the variable i, you cannot do it
in the loop, and (b) the final decrement is a statement, not an expression,
so it has to have a semicolon after.

You can also write

for i in n downto 1 do ….

Note this is inclusive so you have to stop with the last value 1.

You can, of course, use a forward loop and just do a subtraction.



John Skaller
ska...@internode.on.net





Razetime

unread,
Oct 26, 2022, 3:27:22 AM10/26/22
to felix...@googlegroups.com
Oh, neat. Where can I find this in the documentation? I didn't know
about either of these from the tutorial.
> --
> You received this message because you are subscribed to the Google Groups
> "felix" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to felix-lang+...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/felix-lang/AAE6FBE4-1FE3-44C2-BAF7-5FDA4B63E1BD%40internode.on.net.
>

John Skaller

unread,
Oct 27, 2022, 12:02:20 AM10/27/22
to felix


> On 26 Oct 2022, at 18:27, Razetime <rraghu...@gmail.com> wrote:
>
> Oh, neat. Where can I find this in the documentation? I didn't know
> about either of these from the tutorial.

There are some issues with documentation.

The primary system is a server which actually displays real library
and tutorial code. The tutorial code is real, executable, Felix,
including the text.

The web server is flx_web. It’s a standard part of the build. Unfortunately
I’ve had trouble securing an online machine. to run it. The current

http://felix-lang.org/

runs on Amazon and is paid for by a friend but I’ve lost connection with
him. I cannot afford a slice myself.

You don’t have flx_web because your build failed. I’m still trying
to figure out why. I understand the diagnostic and what leads to it,
but the conditions should not arise .. and I can’t explore because I don’t
have a Linux box. If I could get the GitHub Linux CI running it would help.


I also did a set of “readthedocs” tutorials and specifications.

https://felix.readthedocs.io/en/latest/index.html

Unfortunately it keeps breaking and is tiresome to maintain,
as well as the official website (which I cannot maintain anymore eiter).

There are also LaTeX documents in the repository.

https://github.com/felix-lang/felix/blob/master/pdfs/felix-ref.pdf

None of any of these documents are complete.

The best reference is probably the actual source code. For example

src/packages/grammar.fdoc

contains the grammar. In any case, asking on the mailing list is just fine.
The problem of course is know what to ask.




John Skaller
ska...@internode.on.net





Reply all
Reply to author
Forward
0 new messages