Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Switch, Break | Керуючі Оператори
Основи C

bookSwitch, Break

main.c

main.c

copy
1234567891011121314151617
switch (integer_expression) { case first_case_value: // Instruction for this case break; case second_case_value: // Instruction for this case break; case third_case_value: // Instruction for this case break; default: // Default instruction }
Main.c

Main.c

copy
123456789101112131415161718192021222324
#include <stdio.h> int main() { int userInput = 2; switch (userInput) { case 1: printf("You selected cheese-flavored chips.\n"); break; case 2: printf("You selected bacon-flavored chips.\n"); break; case 3: printf("You selected chili-flavored chips.\n"); break; default: printf("You selected another item.\n"); } return 0; }
Note
Примітка
Main.c

Main.c

copy
12345678910111213141516171819202122232425
#include <stdio.h> int main() { char userInput = 'y'; switch (userInput) { case 'a': printf("You entered 'a' character\n"); break; case 'b': printf("You entered 'b' character\n"); break; case 'c': printf("You entered 'c' character\n"); break; default: printf("You entered unknown character\n"); } return 0; }
Main.c

Main.c

copy
123456789101112131415161718192021222324
#include <stdio.h> int main() { char userInput = 'b'; switch (userInput) { case 'a': printf("You entered 'a' character\n"); // without break case 'b': printf("You entered 'b' character\n"); // without break case 'c': printf("You entered 'c' character\n"); // without break default: printf("You entered unknown character\n"); } return 0; }
question mark

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 4

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you show me an example of a switch statement in code?

What happens if I forget to include a break statement in one of the cases?

Can you explain how the default case works in more detail?

bookSwitch, Break

Свайпніть щоб показати меню

main.c

main.c

copy
1234567891011121314151617
switch (integer_expression) { case first_case_value: // Instruction for this case break; case second_case_value: // Instruction for this case break; case third_case_value: // Instruction for this case break; default: // Default instruction }
Main.c

Main.c

copy
123456789101112131415161718192021222324
#include <stdio.h> int main() { int userInput = 2; switch (userInput) { case 1: printf("You selected cheese-flavored chips.\n"); break; case 2: printf("You selected bacon-flavored chips.\n"); break; case 3: printf("You selected chili-flavored chips.\n"); break; default: printf("You selected another item.\n"); } return 0; }
Note
Примітка
Main.c

Main.c

copy
12345678910111213141516171819202122232425
#include <stdio.h> int main() { char userInput = 'y'; switch (userInput) { case 'a': printf("You entered 'a' character\n"); break; case 'b': printf("You entered 'b' character\n"); break; case 'c': printf("You entered 'c' character\n"); break; default: printf("You entered unknown character\n"); } return 0; }
Main.c

Main.c

copy
123456789101112131415161718192021222324
#include <stdio.h> int main() { char userInput = 'b'; switch (userInput) { case 'a': printf("You entered 'a' character\n"); // without break case 'b': printf("You entered 'b' character\n"); // without break case 'c': printf("You entered 'c' character\n"); // without break default: printf("You entered unknown character\n"); } return 0; }
question mark

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 4. Розділ 4
some-alt