Raised This Month: $51 Target: $400
 12% 

Loop Label


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
RumbleFrog
Great Tester of Whatever
Join Date: Dec 2016
Location: Fish Tank
Old 01-16-2018 , 14:26   Loop Label
Reply With Quote #1

Is loop labeling a thing in SourcePawn? Say I want to continue an outer loop inside an inner loop.

PHP Code:
Outer:
for (
int i 0SOMENUMi++)
{
    
Inner:
    for (
int j 0ANOTHERNUMj++)
    {
        if (
/* SOME_CONDITION */)
            continue 
Outer;
        else if (
/* ANOTHER_CONDITION */)
            continue 
Inner;
    }

__________________

Last edited by RumbleFrog; 01-16-2018 at 14:37.
RumbleFrog is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 01-16-2018 , 14:43   Re: Loop Label
Reply With Quote #2

You can use a break in the inner loop, and that should exit to the outer loop and finish it. If there's code after the inner loop that you want to skip you can create some bool and set to true to continue in outer loop. Since I probably explained this poorly here are some code examples:

PHP Code:
for (int i 0SOMENUMi++)
{
    for (
int j 0ANOTHERNUMj++)
    {
        if (
SOME_CONDITION)
            break; 
// exits to outer loop, which will end current outer loop iteration
        
else if (ANOTHER_CONDITION)
            continue;
    }

For skipping other code after inner loop:
PHP Code:
for (int i 0SOMENUMi++)
{
    
skip false;
    for (
int j 0ANOTHERNUMj++)
    {
        if (
SOME_CONDITION)
        {
            
skip true;
            break;
        }
        else if (
ANOTHER_CONDITION)
            continue 
Inner;
    }
    if (
skip)
        continue;

    
// some more code

hmmmmm 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 06:34.


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