Regarding loops
#1

PHP код:
while(2)
    {
        if(
strlen(dmvInfo[i][dmvName]) > 0){
            
format(stringsizeof(string), "%s%d\t%s\t%s\t%s"stringdmvInfo[i][dmvID], dmvInfo[i][dmvName], dmvInfo[i][dmvAuthor], dmvInfo[i][dmvCreationDate]);
            break;
        }
    } 
Above loop won't work if I remove the break, that format is a row from a tablist dialog, the issue is, what if I have more than one value? It will stop on the first find due to 'break;' but if I remove it, it won't work anymore.

I also tried
PHP код:
else {break;} 
and didn't work.


SOLVED, ISSUE WAS THAT I FORGOT TO ADD '\n' FOR NEW ROW
Reply
#2

by won't work do you mean it never finishes? if yes, you've forgot i++ after the check ->
PHP код:
while(2
    { 
        if(
strlen(dmvInfo[i][dmvName]) > 0){ 
            
format(stringsizeof(string), "%s%d\t%s\t%s\t%s"stringdmvInfo[i][dmvID], dmvInfo[i][dmvName], dmvInfo[i][dmvAuthor], dmvInfo[i][dmvCreationDate]); 
        }
        
i++; 
    } 
Reply
#3

By won't work I mean, the dialog won't show if I don't add break; under the format, inside the if statement...

and if I add break; the loop will stop at the first result, and I don't want it to stop at first result.
Reply
#4

Yea the dialog won't work because the loop will never stop as the i < 2 statement always true.

try my code and post result.
Reply
#5

Quote:
Originally Posted by jlalt
Посмотреть сообщение
Yea the dialog won't work because the loop will never stop as the i < 2 statement always true.

try my code and post result.
I did, it still doesn't display, and it is the same with this:
PHP код:

for(new i2i++)
    {
        if(
strlen(dmvInfo[i][dmvName]) > 0)
        {
            
format(stringsizeof(string), "%s%d\t%s\t%s\t%s"stringdmvInfo[i][dmvID], dmvInfo[i][dmvName], dmvInfo[i][dmvAuthor], dmvInfo[i][dmvCreationDate]);
        }
    } 
This doesn't work either.
Reply
#6

It's because you aren't giving i a number. Try this.
Код:
for(new i=0; i < 2; i++)
Reply
#7

Quote:
Originally Posted by frouzen
Посмотреть сообщение
It's because you aren't giving i a number. Try this.
Код:
for(new i=0; i < 2; i++)
pawn isn't c#... if you don't assign value to a integer it will get value 0.

@AndreiWow are you sure the if statement is true? mind debugging? also you may wanna use sizeof ->

PHP код:
    for(new isizeof dmvInfoi++) 
    { 
        
printf("Length of %d: %d",istrlen(dmvInfo[i][dmvName]));
        if(
strlen(dmvInfo[i][dmvName]) > 0
        { 
            
format(stringsizeof(string), "%s%d\t%s\t%s\t%s"stringdmvInfo[i][dmvID], dmvInfo[i][dmvName], dmvInfo[i][dmvAuthor], dmvInfo[i][dmvCreationDate]); 
        } 
    } 
Reply
#8

Quote:
Originally Posted by jlalt
Посмотреть сообщение
pawn isn't c#... if you don't assign value to a integer it will get value 0.
Silly me.
Reply
#9

Quote:
Originally Posted by jlalt
Посмотреть сообщение
pawn isn't c#... if you don't assign value to a integer it will get value 0.

@AndreiWow are you sure the if statement is true? mind debugging? also you may wanna use sizeof ->

PHP код:
    for(new isizeof dmvInfoi++) 
    { 
        
printf("Length of %d: %d",istrlen(dmvInfo[i][dmvName]));
        if(
strlen(dmvInfo[i][dmvName]) > 0
        { 
            
format(stringsizeof(string), "%s%d\t%s\t%s\t%s"stringdmvInfo[i][dmvID], dmvInfo[i][dmvName], dmvInfo[i][dmvAuthor], dmvInfo[i][dmvCreationDate]); 
        } 
    } 
Yes, the if works, and the dialog also works if I add break;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)