Jump to content

while()


Thralni

Recommended Posts

I have been trying to use a while call instead of making hundreds of seperate calls. Problem is, that it doesn't work:

 

Code:
 // Girl comes by	relocate_character(28,22,30);	play_sound(49);	force_instant_terrain_redraw();	pause(3);		y = 29;		while (y < 15) {			relocate_character(28,22,y);			play_sound(49);			force_instant_terrain_redraw();			pause(3);						y = y - 1;			}		relocate_character(28,22,15);	play_sound(49);	force_instant_terrain_redraw();	pause(3);		relocate_character(28,23,14);	play_sound(49);	force_instant_terrain_redraw();	pause(3);		relocate_character(28,24,13);	play_sound(49);	force_instant_terrain_redraw();	pause(3);		y = 12;		while (y < 2) {			relocate_character(28,24,y);			play_sound(49);			force_instant_terrain_redraw();			pause(3);						y = y - 1;			}		erase_char(28); // erase woman	pause(10); 
What's happening now, is that the woman takes one step and then it stops. This happens at both occasions where I used the while call.

 

What I want to happen, is a girl running past the party. Can anybody point out the problem?

Link to comment
Share on other sites

Quote:
Originally written by *i:
At least for the top part of the code, y starts at 29, which is not less than 15, so the loop begins as false and is never entered. I suggest making it "while (y > 15)".
That's exactly the thing I tried to do right. This basically means that my understaning of the command "while" is exactly the other way around: i thought that as long as it's false, it will be done, which doesn't seem to be the thing here.

Thanks.
Link to comment
Share on other sites

By Aran:

Quote:
Yes, it's "while", not "until".

 

(Which supposedly exists in some interpreted languages. I find it hard to believe - what part of "!" is so inconvenient?)

Perl has unless as an alternative to if. The only time I use it is in cases like
Code:
die "Cannot open file: $!\n"    unless fclose($name);# I think I'll leave this typo
Not to useful, though I find having the condition after the statement sometimes makes more sense than a naked if.

 

I've never seen until, though.

 

--------------------

Who needs if when you have Boolean operators?

Link to comment
Share on other sites

Quote:
Originally written by Dintiradan:
Code:
die "Cannot open file: $!\n"    unless fclose($name);
Not to useful, though I find having the condition after the statement sometimes makes more sense than a naked if.
Ironically, this implies that the difference between "if" and "unless" is not primarily that the condition inside must be true or false, but that it precedes or follows the statement.

Why this?

Code:
if (condition) doThis();doThis() unless(!condition);
And not

Code:
doThis() if (condition);unless(!condition) doThis();
? It seems arbitrary...

---

A final nitpick: "die unless tryThis" makes no sense at all from the readability perspective. Are you expecting an error and surprised if it doesn't occur? That's what it looks like...

PHP's way of "tryThis or die" at least makes some superficial sense...
Link to comment
Share on other sites

By Aran:

Quote:
A final nitpick: "die unless tryThis" makes no sense at all from the readability perspective. Are you expecting an error and surprised if it doesn't occur? That's what it looks like...
Actually, the only reason I posted that example is because my instructor always wrote that way. Usually, I write
Code:
fclose($name) || die "Error";
But for some strange reason people find that unreadable. smile

 

Basically, the use of STATEMENT unless CONDITION in Perl stems from Larry's decision not to have naked if statements like C does.

 

Sort of like having elsif because he thinks elseif is ugly...

 

--------------------

C programmers never die. They are just cast into void.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...