Raised This Month: $ Target: $400
 0% 

Instead of the loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yl2401
Member
Join Date: Nov 2011
Old 08-09-2014 , 23:56   Instead of the loop
Reply With Quote #1

Normal:
PHP Code:
for( new ii<maxi++ ) 
if max = 2, "i" had 1 and 2.

Opposite:
PHP Code:
for( new i=maxi>0i-- ) 
if max = 2, "i" had 0 and 1.

1 and 2, how to make it in the opposite?
THANK YOU!

Last edited by yl2401; 08-09-2014 at 23:56.
yl2401 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-10-2014 , 02:58   Re: Instead of the loop
Reply With Quote #2

This question doesn't really make much sense. I think we have an XY Problem here.

Please explain, in detail, what you are actually trying to do.
__________________
fysiks is offline
yl2401
Member
Join Date: Nov 2011
Old 08-10-2014 , 05:21   Re: Instead of the loop
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
This question doesn't really make much sense. I think we have an XY Problem here.

Please explain, in detail, what you are actually trying to do.
I'm making a plugin. This plugin will use the ".ini" save player views. And making a menu to list the player views. Whenever the players to express their views, plugin will be saved to the bottom parts of the file. But I would like to list the latest comments. So I want to instead of the loop. How to do that? THANK YOU!
yl2401 is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-10-2014 , 05:41   Re: Instead of the loop
Reply With Quote #4

So if you want to list the latest 5 entries, do for ( new i=max-5; i < max; i++) or do a decrementing loop to start from the end?
Backstabnoob is offline
yl2401
Member
Join Date: Nov 2011
Old 08-10-2014 , 06:16   Re: Instead of the loop
Reply With Quote #5

Quote:
Originally Posted by Backstabnoob View Post
So if you want to list the latest 5 entries, do for ( new i=max-5; i < max; i++) or do a decrementing loop to start from the end?
THANK YOU! But I want to show the latest one to the first item in menu, show the second one to the second item in menu, and so on. So how to do a decrementing loop?

Last edited by yl2401; 08-10-2014 at 06:18.
yl2401 is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-10-2014 , 07:04   Re: Instead of the loop
Reply With Quote #6

Exactly the way you first posted.

for (new i=max; i > max-5; i--)

Depending on how the 'lines' are indexed, you might have to do new i=max-1.

for () loops are simple, you just need to learn how they work. They consist of three parameters: starting value, condition that dictates when the loop should break and incremental/decremental value.

Last edited by Backstabnoob; 08-10-2014 at 07:10.
Backstabnoob is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 08-10-2014 , 07:33   Re: Instead of the loop
Reply With Quote #7

Quote:
Originally Posted by yl2401 View Post
Normal:
PHP Code:
for( new ii<maxi++ ) 
if max = 2, "i" had 1 and 2.

Opposite:
PHP Code:
for( new i=maxi>0i-- ) 
if max = 2, "i" had 0 and 1.

1 and 2, how to make it in the opposite?
THANK YOU!
what you're saying is wrong
for the first code, if max = 2, i will become 0, then it will become 1, then the loop will stop
for the second code, or opposite as you call it, first i value will be 2(where max=2), second value will be 1 and then it will stop

if you're using arrays beware that usually cell alocation starts from pos 0 and ends in pos max-1, so the last character is a string ender(or whatever it's called in english)
so you might wanna go for
PHP Code:
for(new i=max-1;i>=0;i--) 
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:12.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode