Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,310 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
for loop with blank comparison statement #358235
02/09/11 23:37
02/09/11 23:37
Joined: Feb 2011
Posts: 135
Myrkling Offline OP
Member
Myrkling  Offline OP
Member

Joined: Feb 2011
Posts: 135
Code:
for (i = 0; ; i++) { ... }


This compiles fine in 8.10.1, but causes random crashes during runtime ("Crash in SYS").

As this relation is not that obvious, it should be mentioned in the manual (or fixed) I think.

Re: for loop with blank comparison statement [Re: Myrkling] #358278
02/10/11 10:10
02/10/11 10:10
Joined: Jul 2005
Posts: 1,930
Austria
Dark_samurai Offline
Serious User
Dark_samurai  Offline
Serious User

Joined: Jul 2005
Posts: 1,930
Austria
Code:
for (int i = 0; i < 100; i++) {...}



It's also not possible to declare a variable in a for loop. It would be great if this would be possible too.


ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)!
get free version
Re: for loop with blank comparison statement [Re: Dark_samurai] #358282
02/10/11 10:50
02/10/11 10:50
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
May I ask a newbi question?
What is a for loop without comparison good for, and how does it work?

Re: for loop with blank comparison statement [Re: Pappenheimer] #358285
02/10/11 11:48
02/10/11 11:48
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Well, its useful in the case when you want an iterator in an endless loop. Its the same as:
Code:
int i;

i = 0;
while(1)
{
   // foo
   i++;
}


(imo for(i=0; ; i++) is less ugly)

The C Standard allows you to have any or none of the components set in a for loop, so this would be also possible: for(;;) {} or just for(;;i++) { }.
And Dark_Samurai: Declaring variables in an for loop is C99 and imo Lite-C only aimes compatibility to a subset of C89.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: for loop with blank comparison statement [Re: WretchedSid] #358290
02/10/11 13:37
02/10/11 13:37
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
But, within Acknex you can't use an endless loop without "wait(1);". How does C handle endless loops? I thought, such loop aways needs an interuption.

Re: for loop with blank comparison statement [Re: Pappenheimer] #358292
02/10/11 13:58
02/10/11 13:58
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
You can have an endless loop, and in GUI application you actually should have one.
The problem with Acknex and endless loops is that Acknex never gets the control back and can't draw a new frame or respond to Windows events. Thus Windows thinks your application has stopped responding and marks it as irresponsive.

But in the background of Acknex there is at leas one while() loop, mainly the one which fires the drawing and the responding to windows events.
A typical application life cycle looks like this:

Code:
while(notTerminated)
{
    dispatchEvents();
    updateUI();

    // Do some other stuff
}


(This is btw the perfect place to do non-blocking socket stuff to have asynchronous networking in the main thread)


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: for loop with blank comparison statement [Re: WretchedSid] #358294
02/10/11 14:44
02/10/11 14:44
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Thanks a lot for your explanations! laugh

Re: for loop with blank comparison statement [Re: Pappenheimer] #358440
02/11/11 10:56
02/11/11 10:56
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
For loops allow empty statements, but they do not allow definining variables. This is C standard syntax. A random crash message means you have a random crash in your script, but has nothing to do with empty statements in for loops.

Re: for loop with blank comparison statement [Re: jcl] #358441
02/11/11 11:19
02/11/11 11:19
Joined: Jan 2011
Posts: 122
GUILIN , CHINA
tzw Offline
Member
tzw  Offline
Member

Joined: Jan 2011
Posts: 122
GUILIN , CHINA
but in c99 it work i think


Full of my eyes are class struggles.....
Re: for loop with blank comparison statement [Re: tzw] #358449
02/11/11 12:03
02/11/11 12:03
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Yes, variable declaration in for loops is part of the C99 standard
(http://open-std.org/JTC1/SC22/WG14/www/docs/n897.pdf page 84 and 85)


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Page 1 of 2 1 2

Moderated by  aztec, Inestical, Matt_Coles, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1