Beginners_-_Goto_Label.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "raylib.h"
  2. int main(void)
  3. {
  4. // Initialization
  5. //--------------------------------------------------------------------------------------
  6. const int screenWidth = 800;
  7. const int screenHeight = 450;
  8. InitWindow(screenWidth, screenHeight, "raylib example.");
  9. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  10. //--------------------------------------------------------------------------------------
  11. // Goto label: example.
  12. //
  13. // With a goto you can jump out of nested loop immediately.
  14. int i=0;
  15. while(1){
  16. i++;
  17. if(i>1000)goto label;
  18. }
  19. label:{}; //notice the code block that needs to be there to work.
  20. // Main game loop
  21. while (!WindowShouldClose()) // Detect window close button or ESC key
  22. {
  23. // Update
  24. //----------------------------------------------------------------------------------
  25. //----------------------------------------------------------------------------------
  26. // Draw
  27. //----------------------------------------------------------------------------------
  28. BeginDrawing();
  29. ClearBackground(RAYWHITE);
  30. DrawText("Goto example..worked!",100,100,20,DARKGRAY);
  31. EndDrawing();
  32. //----------------------------------------------------------------------------------
  33. }
  34. // De-Initialization
  35. //--------------------------------------------------------------------------------------
  36. CloseWindow(); // Close window and OpenGL context
  37. //--------------------------------------------------------------------------------------
  38. return 0;
  39. }