As far as i can remember use of goto is considered to be a bad practise, because it can lead to "spaghetti" code.
One useful way to use it is to get out of nested loops.
Also it's naming convention is Ex: skip_loop_block. ? ( with _? ? ?after_each_word )
I'm not sure if that is correct, i never had a need to use it or learn how to use it so...
One useful way to use it is to get out of nested loops.
Also it's naming convention is Ex: skip_loop_block. ? ( with _? ? ?after_each_word )
I'm not sure if that is correct, i never had a need to use it or learn how to use it so...
Code:
new sometext[ 10 ][ 20 ][ 128 ];
// ...
public OnGameModeInit( playerid )
{
// ...
? ? format( sometext[ 1 ][ 2 ], 63, "Print this one" );
? ? format( sometext[ 2 ][ 4 ], 63, "Print this one too." );
? ? format( sometext[ 3 ][ 8 ], 63, "Print, print, print!" );
? ? format( sometext[ 4 ][ 16 ], 63, "End nested loop NOW!" );
? ? format( sometext[ 5 ][ 19 ], 63, "This one will not be printed!" );
for( new i; i < 10; i )
{
for( new j; j < 20; j )
{
? ? if( !isnull( sometext[ i ][ j ] ) )
? ? {
? ? if( strcmp( "End nested loop NOW!", sometext[ i ][ j ], false ) == 0 )
? ? {
? ? goto skip_loop_block; // we don't have to break; 2 loops now!
? ? }
? ? else printf( "%s", sometext[ i ][ j ] );
? ? }
}
}
printf( "This one will not be printed if we use goto!" );
skip_loop_block:
print( "Done" );
return 1;
}