Beginners_-_switch_default.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. enum flag{rub,adub,bub};
  2. #include "raylib.h"
  3. int main(void)
  4. {
  5. // Initialization
  6. //--------------------------------------------------------------------------------------
  7. const int screenWidth = 800;
  8. const int screenHeight = 450;
  9. InitWindow(screenWidth, screenHeight, "raylib example.");
  10. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  11. //--------------------------------------------------------------------------------------
  12. // Main game loop
  13. while (!WindowShouldClose()) // Detect window close button or ESC key
  14. {
  15. // Update
  16. //----------------------------------------------------------------------------------
  17. //----------------------------------------------------------------------------------
  18. // Draw
  19. //----------------------------------------------------------------------------------
  20. BeginDrawing();
  21. ClearBackground(RAYWHITE);
  22. //
  23. // Here we show how to use a switch statement.
  24. //
  25. // Note that you can not initialize arrays inside switch cases.
  26. int what=3;
  27. switch (what){
  28. case rub:
  29. break;
  30. case adub:
  31. //int i=0; <<<<<<< You can not initialize things like this in a case label :
  32. //for(int i=0;i<10;i++){//<<<<<<<<< You can do these things in the switch statements.
  33. //int a=10; <<<<<< Here you can initialize ints.
  34. //};
  35. break;
  36. case bub:
  37. break;
  38. default:
  39. DrawText("default switch case.",100,200,30,GRAY);
  40. break;
  41. }
  42. EndDrawing();
  43. //----------------------------------------------------------------------------------
  44. }
  45. // De-Initialization
  46. //--------------------------------------------------------------------------------------
  47. CloseWindow(); // Close window and OpenGL context
  48. //--------------------------------------------------------------------------------------
  49. return 0;
  50. }