• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Post your code snippets here
#17
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...





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; }
  Reply


Messages In This Thread
Post your code snippets here - by DTV - 2019-04-14, 11:04 PM
RE: Post your code snippets here - by iSpark - 2019-04-15, 03:50 AM
RE: Post your code snippets here - by DTV - 2019-04-15, 07:07 AM
RE: Post your code snippets here - by BlackBank - 2019-04-15, 05:17 PM
RE: Post your code snippets here - by Codeah - 2019-04-15, 06:55 PM
RE: Post your code snippets here - by Riddick - 2019-04-16, 06:24 AM
RE: Post your code snippets here - by Y_Less - 2019-04-16, 11:23 AM
RE: Post your code snippets here - by DTV - 2019-04-16, 06:10 PM
RE: Post your code snippets here - by KJason - 2019-04-16, 11:48 AM
RE: Post your code snippets here - by kristo - 2019-04-16, 12:50 PM
RE: Post your code snippets here - by Mike - 2019-04-17, 02:45 AM
RE: Post your code snippets here - by DTV - 2019-04-29, 07:24 PM
RE: Post your code snippets here - by DTV - 2020-01-03, 06:33 PM
RE: Post your code snippets here - by Awide - 2020-10-18, 07:33 PM
RE: Post your code snippets here - by Expert* - 2020-10-24, 12:40 PM
RE: Post your code snippets here - by Virsenas - 2021-02-26, 11:53 PM
RE: Post your code snippets here - by Tama - 2021-10-27, 03:59 PM